forked from dfar2008/c3crm
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathDoSendPwd.php
115 lines (108 loc) · 2.91 KB
/
DoSendPwd.php
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
<?php
require_once('config.php');
require_once('modules/Users/Users.php');
require_once('include/logging.php');
require_once('include/utils/UserInfoUtil.php');
require_once('dosendmail.php');
global $adb;
$user_email = $_REQUEST['user_email'];
$query = "SELECT id FROM ec_users WHERE deleted=0 and email1 ='".$user_email."'";
$row = $adb->getFirstLine($query);
if(empty($row))
{
echo 'Email:',$user_email,'不存在!';
die;
}
else
{
$id = $row['id'];
$last_name = $row['last_name'];
$len = 6;
// 随机生成数组索引,从而实现随机数
for($j=0; $j<100; $j++)
{
$pass = "";
$options = getOptions();
$lastIndex = 35;
while (strlen($pass)<$len)
{
// 从0到35中随机取一个作为索引
$index = rand(0,$lastIndex);
// 将随机数赋给变量 $chr
$chr = $options[$index];
// 随机数作为 $pass 的一部分
$pass .= $chr;
$lastIndex = $lastIndex-1;
// 最后一个索引将不会参与下一次随机抽奖
$options[$index] = $options[$lastIndex];
}
}
//生成新的密码
$focus = new Users();
$new_password = $focus->encrypt_password($pass);
$user_hash = strtolower(md5($pass));
//change pwd to new pwd
$query = "UPDATE ec_users SET user_password='$new_password', user_hash='$user_hash' where id='$id'";
$adb->query($query);
/*
$mail = new SaeMail();
$subject = "找回密码";
$content = "尊敬的用户,您好,易客CRM已经收到您的找回密码请求,现已将您的密码重置为:".$pass.",请重新登录后修改.";
global $log;
$log->info($content);
$sql="select * from ec_systems where server_type = 'email' and smownerid='$id'";
$server_row = $adb->getFirstLine($sql);
if(empty($server_row))
{
$from_email = "[email protected]";
$pwd = "c3crm321";
$server_name ="smtp.sina.com";
$server_port = "25";
}else{
$from_email = $server_row['from_email'];
$pwd = $server_row['server_password'];
$server_name = $server_row['server'];
$server_port = $server_row['server_port'];
}
$ret = $mail->quickSend( $user_email , $subject , $content , $from_email , $pwd ,$server_name , $server_port);
if ($ret === false)
{ $errMsg = $mail->errmsg();
echo '发送失败'.$pass;
die;
}else{
echo '发送成功';
die;
}*/
//change pwd to new pwd
$subject = "找回密码";
$content = "尊敬的用户,您好,易客CRM已经收到您的找回密码请求,现已将您的密码重置为:".$pass.",请重新登录后修改.";
global $log;
$log->info($content);
$msg = send_webmail($user_email,$last_name,'','',$subject,$content,'',$id);
if(!empty($msg))
{
echo '发送失败'.$msg;
die;
}else{
echo '发送成功';
die;
}
}
// 生成0123456789abcdefghijklmnopqrstuvwxyz中的一个字符
function getOptions()
{
$options = array();
$result = array();
for($i=48; $i<=57; $i++)
{
array_push($options,chr($i));
}
for($i=65; $i<=90; $i++)
{
$j = 32;
$small = $i + $j;
array_push($options,chr($small));
}
return $options;
}
?>