3 require_once('include/email.php');
4 require_once('include/enotify.php');
6 function lostpass_post(&$a) {
8 $loginame = notags(trim($_POST['login-name']));
12 $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) AND `verified` = 1 AND `blocked` = 0 LIMIT 1",
18 notice( t('No valid account found.') . EOL);
23 $username = $r[0]['username'];
24 $email = $r[0]['email'];
26 $new_password = autoname(12) . mt_rand(100,9999);
27 $new_password_encoded = hash('whirlpool',$new_password);
29 $r = q("UPDATE `user` SET `pwdreset` = '%s' WHERE `uid` = %d",
30 dbesc($new_password_encoded),
34 info( t('Password reset request issued. Check your email.') . EOL);
37 $sitename = $a->config['sitename'];
38 $siteurl = $a->get_baseurl();
39 $resetlink = $a->get_baseurl() . '/lostpass?verify=' . $new_password;
41 $preamble = t('Dear %1$s,
42 A request was recently received at "%2$s" to reset your account
43 password. In order to confirm this request, please select the verification link
44 below or paste it into your web browser address bar.
46 If you did NOT request this change, please DO NOT follow the link
47 provided and ignore and/or delete this email.
49 Your password will not be changed unless we can verify that you
50 issued this request.');
51 $body = t('Follow this link to verify your identity:
55 You will then receive a follow-up message containing the new password.
57 You may change that password from your account settings page after logging in.
59 The login details are as follows:
64 $preamble = sprintf($preamble, $username, $sitename);
65 $body = sprintf($body, $resetlink, $siteurl, $email);
68 'type' => "SYSTEM_EMAIL",
70 'subject'=> sprintf( t('Password reset requested at %s'),$sitename),
71 'preamble'=> $preamble,
80 function lostpass_content(&$a) {
83 if(x($_GET,'verify')) {
84 $verify = $_GET['verify'];
85 $hash = hash('whirlpool', $verify);
87 $r = q("SELECT * FROM `user` WHERE `pwdreset` = '%s' LIMIT 1",
91 notice( t("Request could not be verified. \x28You may have previously submitted it.\x29 Password reset failed.") . EOL);
96 $username = $r[0]['username'];
97 $email = $r[0]['email'];
99 $new_password = autoname(6) . mt_rand(100,9999);
100 $new_password_encoded = hash('whirlpool',$new_password);
102 $r = q("UPDATE `user` SET `password` = '%s', `pwdreset` = '' WHERE `uid` = %d",
103 dbesc($new_password_encoded),
107 $tpl = get_markup_template('pwdreset.tpl');
108 $o .= replace_macros($tpl,array(
109 '$lbl1' => t('Password Reset'),
110 '$lbl2' => t('Your password has been reset as requested.'),
111 '$lbl3' => t('Your new password is'),
112 '$lbl4' => t('Save or copy your new password - and then'),
113 '$lbl5' => '<a href="' . $a->get_baseurl() . '">' . t('click here to login') . '</a>.',
114 '$lbl6' => t('Your password may be changed from the <em>Settings</em> page after successful login.'),
115 '$newpass' => $new_password,
116 '$baseurl' => $a->get_baseurl()
119 info("Your password has been reset." . EOL);
123 $email_tpl = get_intltext_template("passchanged_eml.tpl");
124 $email_tpl = replace_macros($email_tpl, array(
125 '$sitename' => $a->config['sitename'],
126 '$siteurl' => $a->get_baseurl(),
127 '$username' => $username,
129 '$new_password' => $new_password,
130 '$uid' => $newuid ));
132 $subject = sprintf( t('Your password has been changed at %s'), $a->config['sitename']);
134 $res = mail($email, email_header_encode( $subject, 'UTF-8'), $email_tpl,
135 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
136 . 'Content-type: text/plain; charset=UTF-8' . "\n"
137 . 'Content-transfer-encoding: 8bit' );
144 $tpl = get_markup_template('lostpass.tpl');
146 $o .= replace_macros($tpl,array(
147 '$title' => t('Forgot your Password?'),
148 '$desc' => t('Enter your email address and submit to have your password reset. Then check your email for further instructions.'),
149 '$name' => t('Nickname or Email: '),
150 '$submit' => t('Reset')