5 require_once('include/email.php');
6 require_once('include/enotify.php');
7 require_once('include/text.php');
9 function lostpass_post(App $a) {
11 $loginame = notags(trim($_POST['login-name']));
15 $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) AND `verified` = 1 AND `blocked` = 0 LIMIT 1",
20 if (! dbm::is_result($r)) {
21 notice( t('No valid account found.') . EOL);
26 $username = $r[0]['username'];
27 $email = $r[0]['email'];
29 $new_password = autoname(12) . mt_rand(100,9999);
30 $new_password_encoded = hash('whirlpool',$new_password);
32 $r = q("UPDATE `user` SET `pwdreset` = '%s' WHERE `uid` = %d",
33 dbesc($new_password_encoded),
37 info( t('Password reset request issued. Check your email.') . EOL);
40 $sitename = $a->config['sitename'];
41 $resetlink = App::get_baseurl() . '/lostpass?verify=' . $new_password;
43 $preamble = deindent(t('
45 A request was recently received at "%2$s" to reset your account
46 password. In order to confirm this request, please select the verification link
47 below or paste it into your web browser address bar.
49 If you did NOT request this change, please DO NOT follow the link
50 provided and ignore and/or delete this email.
52 Your password will not be changed unless we can verify that you
53 issued this request.'));
55 Follow this link to verify your identity:
59 You will then receive a follow-up message containing the new password.
60 You may change that password from your account settings page after logging in.
62 The login details are as follows:
67 $preamble = sprintf($preamble, $username, $sitename);
68 $body = sprintf($body, $resetlink, App::get_baseurl(), $email);
71 'type' => "SYSTEM_EMAIL",
73 'subject'=> sprintf( t('Password reset requested at %s'),$sitename),
74 'preamble'=> $preamble,
82 function lostpass_content(App $a) {
85 if(x($_GET,'verify')) {
86 $verify = $_GET['verify'];
87 $hash = hash('whirlpool', $verify);
89 $r = q("SELECT * FROM `user` WHERE `pwdreset` = '%s' LIMIT 1",
92 if (! dbm::is_result($r)) {
93 $o = t("Request could not be verified. \x28You may have previously submitted it.\x29 Password reset failed.");
97 $username = $r[0]['username'];
98 $email = $r[0]['email'];
100 $new_password = autoname(6) . mt_rand(100,9999);
101 $new_password_encoded = hash('whirlpool',$new_password);
103 $r = q("UPDATE `user` SET `password` = '%s', `pwdreset` = '' WHERE `uid` = %d",
104 dbesc($new_password_encoded),
108 /// @TODO Is dbm::is_result() okay here?
110 $tpl = get_markup_template('pwdreset.tpl');
111 $o .= replace_macros($tpl,array(
112 '$lbl1' => t('Password Reset'),
113 '$lbl2' => t('Your password has been reset as requested.'),
114 '$lbl3' => t('Your new password is'),
115 '$lbl4' => t('Save or copy your new password - and then'),
116 '$lbl5' => '<a href="' . App::get_baseurl() . '">' . t('click here to login') . '</a>.',
117 '$lbl6' => t('Your password may be changed from the <em>Settings</em> page after successful login.'),
118 '$newpass' => $new_password,
119 '$baseurl' => App::get_baseurl()
122 info("Your password has been reset." . EOL);
125 $sitename = $a->config['sitename'];
126 // $username, $email, $new_password
127 $preamble = deindent(t('
129 Your password has been changed as requested. Please retain this
130 information for your records (or change your password immediately to
131 something that you will remember).
134 Your login details are as follows:
140 You may change that password from your account settings page after logging in.
143 $preamble = sprintf($preamble, $username);
144 $body = sprintf($body, App::get_baseurl(), $email, $new_password);
147 'type' => "SYSTEM_EMAIL",
148 'to_email' => $email,
149 'subject'=> sprintf( t('Your password has been changed at %s'),$sitename),
150 'preamble'=> $preamble,
158 $tpl = get_markup_template('lostpass.tpl');
160 $o .= replace_macros($tpl,array(
161 '$title' => t('Forgot your Password?'),
162 '$desc' => t('Enter your email address and submit to have your password reset. Then check your email for further instructions.'),
163 '$name' => t('Nickname or Email: '),
164 '$submit' => t('Reset')