国内流行的内容管理系统(CMS)多端全媒体解决方案 https://www.dedebiz.com
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

158 lines
5.9KB

  1. <?php
  2. if (!defined('DEDEINC')) exit ('dedebiz');
  3. /**
  4. * 密码函数
  5. *
  6. * @version $id:inc_pwd_functions.php 15:18 2010年7月9日 tianya $
  7. * @package DedeBIZ.User
  8. * @copyright Copyright (c) 2022 DedeBIZ.COM
  9. * @license https://www.dedebiz.com/license
  10. * @link https://www.dedebiz.com
  11. */
  12. /**
  13. * 验证码生成函数
  14. *
  15. * @param int $length 需要生成的长度
  16. * @param int $numeric 是否为数字
  17. * @return string
  18. */
  19. function random($length, $numeric = 0)
  20. {
  21. PHP_VERSION < '4.2.0' && mt_srand((float)microtime() * 1000000);
  22. if ($numeric) {
  23. $hash = sprintf('%0'.$length.'d', mt_rand(0, pow(10, $length) - 1));
  24. } else {
  25. $hash = '';
  26. $chars = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789abcdefghijklmnopqrstuvwxyz';
  27. $max = strlen($chars) - 1;
  28. for ($i = 0; $i < $length; $i++) {
  29. $hash .= $chars[mt_rand(0, $max)];
  30. }
  31. }
  32. return $hash;
  33. }
  34. /**
  35. * 邮件发送函数
  36. *
  37. * @param string $email E-mail地址
  38. * @param string $mailtitle E-mail标题
  39. * @param string $mailbody E-mail文档
  40. * @param string $headers 头信息
  41. * @return void
  42. */
  43. function sendmail($email, $mailtitle, $mailbody, $headers)
  44. {
  45. global $cfg_sendmail_bysmtp, $cfg_smtp_server, $cfg_smtp_port, $cfg_smtp_usermail, $cfg_smtp_user, $cfg_smtp_password, $cfg_adminemail, $cfg_bizcore_appid, $cfg_bizcore_key;
  46. if (!empty($cfg_bizcore_appid) && !empty($cfg_bizcore_key)) {
  47. $client = new DedeBizClient();
  48. $client->MailSend($email,$mailtitle,$mailtitle,$mailbody);
  49. $client->Close();
  50. } else {
  51. if ($cfg_sendmail_bysmtp == 'Y') {
  52. $mailtype = 'TXT';
  53. require_once(DEDEINC.'/libraries/mail.class.php');
  54. $smtp = new smtp($cfg_smtp_server, $cfg_smtp_port, true, $cfg_smtp_usermail, $cfg_smtp_password);
  55. $smtp->debug = false;
  56. $smtp->sendmail($email, $cfg_webname, $cfg_smtp_usermail, $mailtitle, $mailbody, $mailtype);
  57. } else {
  58. @mail($email, $mailtitle, $mailbody, $headers);
  59. }
  60. }
  61. }
  62. /**
  63. * 发送邮件,type为INSERT新建验证码,UPDATE修改验证码
  64. *
  65. * @param int $mid 会员id
  66. * @param int $userid 会员id
  67. * @param string $mailto 发送到
  68. * @param string $type 类型
  69. * @param string $send 发送到
  70. * @return string
  71. */
  72. function newmail($mid, $userid, $mailto, $type, $send)
  73. {
  74. global $db, $cfg_adminemail, $cfg_webname, $cfg_basehost, $cfg_memberurl;
  75. $mailtime = time();
  76. $randval = random(8);
  77. $mailtitle = $cfg_webname.":密码修改";
  78. $mailto = $mailto;
  79. $headers = "From:".$cfg_adminemail."\r\nReply-To:$cfg_adminemail";
  80. $mailbody = "尊敬的".$userid."会员,临时登录密码:".$randval."\r\n请在三天内修改登录密码:".$cfg_basehost.$cfg_memberurl."/resetpassword.php?dopost=getpasswd&id=".$mid;
  81. if ($type == 'INSERT') {
  82. $key = md5($randval);
  83. $sql = "INSERT INTO `#@__pwd_tmp` (`mid` ,`membername` ,`pwd` ,`mailtime`) VALUES ('$mid', '$userid', '$key', '$mailtime');";
  84. if ($db->ExecuteNoneQuery($sql)) {
  85. if ($send == 'Y') {
  86. sendmail($mailto, $mailtitle, $mailbody, $headers);
  87. return ShowMsg('验证码已经发送到原来的邮箱,请注意查收', 'login.php', '', '5000');
  88. } else if ($send == 'N') {
  89. return ShowMsg('稍后前往修改页', $cfg_basehost.$cfg_memberurl."/resetpassword.php?dopost=getpasswd&id=".$mid."&key=".$randval);
  90. }
  91. } else {
  92. return ShowMsg('修改失败,请联系管理员', 'login.php');
  93. }
  94. } elseif ($type == 'UPDATE') {
  95. $key = md5($randval);
  96. $sql = "UPDATE `#@__pwd_tmp` SET `pwd` = '$key',mailtime = '$mailtime' WHERE `mid` ='$mid';";
  97. if ($db->ExecuteNoneQuery($sql)) {
  98. if ($send === 'Y') {
  99. sendmail($mailto, $mailtitle, $mailbody, $headers);
  100. ShowMsg('修改验证码已经发送到原来的邮箱请查收', 'login.php');
  101. } elseif ($send === 'N') {
  102. return ShowMsg('稍后前往修改页', $cfg_basehost.$cfg_memberurl."/resetpassword.php?dopost=getpasswd&id=".$mid."&key=".$randval);
  103. }
  104. } else {
  105. ShowMsg('修改失败,请与管理员联系', 'login.php');
  106. }
  107. }
  108. }
  109. /**
  110. * 查询会员信息,mail会员输入邮箱地址,userid会员名
  111. *
  112. * @param string $mail 邮件
  113. * @param string $userid 会员id
  114. * @return mixed
  115. */
  116. function member($mail, $userid)
  117. {
  118. global $db;
  119. $msql = empty($mail)? "1=1" : "email='$mail'";
  120. $sql = "SELECT mid,email,safequestion FROM `#@__member` WHERE $msql AND userid = '$userid'";
  121. $row = $db->GetOne($sql);
  122. if (!is_array($row)) {
  123. ShowMsg("会员id输入错误", "-1");
  124. exit;
  125. } else {
  126. return $row;
  127. }
  128. }
  129. /**
  130. * 查询是否发送过验证码
  131. *
  132. * @param string $mid 会员id
  133. * @param string $userid 会员名称
  134. * @param string $mailto 发送邮件地址
  135. * @param string $send 为Y发送邮件,为N不发送邮件默认为Y
  136. * @return string
  137. */
  138. function sn($mid, $userid, $mailto, $send = 'Y')
  139. {
  140. global $db;
  141. $tptim = (60 * 10);
  142. $dtime = time();
  143. $sql = "SELECT * FROM `#@__pwd_tmp` WHERE mid = '$mid'";
  144. $row = $db->GetOne($sql);
  145. //发送新邮件
  146. if (!is_array($row)) {
  147. newmail($mid, $userid, $mailto, 'INSERT', $send);
  148. }
  149. //10分钟后可以再次发送新验证码
  150. elseif ($dtime - $tptim > $row['mailtime']) {
  151. newmail($mid, $userid, $mailto, 'UPDATE', $send);
  152. }
  153. //重新发送新的验证码确认邮件
  154. else {
  155. return ShowMsg('请10分钟后再重新申请', 'login.php');
  156. }
  157. }
  158. ?>