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

155 lines
6.2KB

  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;
  46. global $cfg_bizcore_appid,$cfg_bizcore_key,$cfg_bizcore_hostname,$cfg_bizcore_port;
  47. if (!empty($cfg_bizcore_appid) && !empty($cfg_bizcore_key)) {
  48. $client = new DedeBizClient($cfg_bizcore_hostname, $cfg_bizcore_port);
  49. $client->appid = $cfg_bizcore_appid;
  50. $client->key = $cfg_bizcore_key;
  51. $client->MailSend($email,$mailtitle,$mailtitle,$mailbody);
  52. $client->Close();
  53. } else {
  54. if ($cfg_sendmail_bysmtp == 'Y') {
  55. $mailtype = 'TXT';
  56. require_once(DEDEINC.'/libraries/mail.class.php');
  57. $smtp = new smtp($cfg_smtp_server, $cfg_smtp_port, true, $cfg_smtp_usermail, $cfg_smtp_password);
  58. $smtp->debug = false;
  59. $smtp->sendmail($email, $cfg_webname, $cfg_smtp_usermail, $mailtitle, $mailbody, $mailtype);
  60. } else {
  61. @mail($email, $mailtitle, $mailbody, $headers);
  62. }
  63. }
  64. }
  65. /**
  66. * 发送邮件;type为INSERT新建验证码,UPDATE修改验证码;
  67. *
  68. * @param int $mid 会员id
  69. * @param int $userid 用户id
  70. * @param string $mailto 发送到
  71. * @param string $type 类型
  72. * @param string $send 发送到
  73. * @return string
  74. */
  75. function newmail($mid, $userid, $mailto, $type, $send)
  76. {
  77. global $db, $cfg_adminemail, $cfg_webname, $cfg_basehost, $cfg_memberurl;
  78. $mailtime = time();
  79. $randval = random(8);
  80. $mailtitle = $cfg_webname.":密码修改";
  81. $mailto = $mailto;
  82. $headers = "From: ".$cfg_adminemail."\r\nReply-To: $cfg_adminemail";
  83. $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;
  84. if ($type == 'INSERT') {
  85. $key = md5($randval);
  86. $sql = "INSERT INTO `#@__pwd_tmp` (`mid` ,`membername` ,`pwd` ,`mailtime`) VALUES ('$mid', '$userid', '$key', '$mailtime');";
  87. if ($db->ExecuteNoneQuery($sql)) {
  88. if ($send == 'Y') {
  89. sendmail($mailto, $mailtitle, $mailbody, $headers);
  90. return ShowMsg('EMAIL修改验证码已经发送到原来的邮箱请查收', 'login.php', '', '5000');
  91. } else if ($send == 'N') {
  92. return ShowMsg('稍后跳转修改页', $cfg_basehost.$cfg_memberurl."/resetpassword.php?dopost=getpasswd&amp;id=".$mid."&amp;key=".$randval);
  93. }
  94. } else {
  95. return ShowMsg('对不起修改失败,请联系管理员', 'login.php');
  96. }
  97. } elseif ($type == 'UPDATE') {
  98. $key = md5($randval);
  99. $sql = "UPDATE `#@__pwd_tmp` SET `pwd` = '$key',mailtime = '$mailtime' WHERE `mid` ='$mid';";
  100. if ($db->ExecuteNoneQuery($sql)) {
  101. if ($send === 'Y') {
  102. sendmail($mailto, $mailtitle, $mailbody, $headers);
  103. ShowMsg('EMAIL修改验证码已经发送到原来的邮箱请查收', 'login.php');
  104. } elseif ($send === 'N') {
  105. return ShowMsg('稍后跳转修改页', $cfg_basehost.$cfg_memberurl."/resetpassword.php?dopost=getpasswd&amp;id=".$mid."&amp;key=".$randval);
  106. }
  107. } else {
  108. ShowMsg('对不起修改失败,请与管理员联系', 'login.php');
  109. }
  110. }
  111. }
  112. /**
  113. * 查询会员信息mail用户输入邮箱地址;userid用户名
  114. *
  115. * @param string $mail 邮件
  116. * @param string $userid 用户id
  117. * @return string
  118. */
  119. function member($mail, $userid)
  120. {
  121. global $db;
  122. $sql = "SELECT mid,email,safequestion FROM `#@__member` WHERE email='$mail' AND userid = '$userid'";
  123. $row = $db->GetOne($sql);
  124. if (!is_array($row)) return ShowMsg("对不起,用户id输入错误", "-1");
  125. else return $row;
  126. }
  127. /**
  128. * 查询是否发送过验证码
  129. *
  130. * @param string $mid 会员id
  131. * @param string $userid 用户名称
  132. * @param string $mailto 发送邮件地址
  133. * @param string $send 为Y发送邮件,为N不发送邮件默认为Y
  134. * @return string
  135. */
  136. function sn($mid, $userid, $mailto, $send = 'Y')
  137. {
  138. global $db;
  139. $tptim = (60 * 10);
  140. $dtime = time();
  141. $sql = "SELECT * FROM `#@__pwd_tmp` WHERE mid = '$mid'";
  142. $row = $db->GetOne($sql);
  143. if (!is_array($row)) {
  144. //发送新邮件;
  145. newmail($mid, $userid, $mailto, 'INSERT', $send);
  146. }
  147. //10分钟后可以再次发送新验证码;
  148. elseif ($dtime - $tptim > $row['mailtime']) {
  149. newmail($mid, $userid, $mailto, 'UPDATE', $send);
  150. }
  151. //重新发送新的验证码确认邮件;
  152. else {
  153. return ShowMsg('对不起,请10分钟后再重新申请', 'login.php');
  154. }
  155. }