国内流行的内容管理系统(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.

159 lines
6.2KB

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