4 function lostpass_post(&$a) {
6 $email = notags(trim($_POST['login-name']));
8 goaway($a->get_baseurl());
10 $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) LIMIT 1",
15 goaway($a->get_baseurl());
17 $username = $r[0]['username'];
19 $new_password = autoname(12) . mt_rand(100,9999);
20 $new_password_encoded = hash('whirlpool',$new_password);
22 $r = q("UPDATE `user` SET `pwdreset` = '%s' WHERE `uid` = %d LIMIT 1",
23 dbesc($new_password_encoded),
27 notice( t('Password reset request issued. Check your email.') . EOL);
29 $email_tpl = load_view_file("view/lostpass_eml.tpl");
30 $email_tpl = replace_macros($email_tpl, array(
31 '$sitename' => $a->config['sitename'],
32 '$siteurl' => $a->get_baseurl(),
33 '$username' => $username,
35 '$reset_link' => $a->get_baseurl() . '/lostpass?verify=' . $new_password
38 $res = mail($email, sprintf( t('Password reset requested at %s'),$a->config['sitename']),
40 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
41 . 'Content-type: text/plain; charset=UTF-8' . "\n"
42 . 'Content-transfer-encoding: 8bit' );
45 goaway($a->get_baseurl());
49 function lostpass_content(&$a) {
52 if(x($_GET,'verify')) {
53 $verify = $_GET['verify'];
54 $hash = hash('whirlpool', $verify);
56 $r = q("SELECT * FROM `user` WHERE `pwdreset` = '%s' LIMIT 1",
60 notice( t("Request could not be verified. \x28You may have previously submitted it.\x29 Password reset failed.") . EOL);
61 goaway($a->get_baseurl());
65 $username = $r[0]['username'];
66 $email = $r[0]['email'];
68 $new_password = autoname(6) . mt_rand(100,9999);
69 $new_password_encoded = hash('whirlpool',$new_password);
71 $r = q("UPDATE `user` SET `password` = '%s', `pwdreset` = '' WHERE `uid` = %d LIMIT 1",
72 dbesc($new_password_encoded),
76 $tpl = load_view_file('view/pwdreset.tpl');
77 $o .= replace_macros($tpl,array(
78 '$lbl1' => t('Password Reset'),
79 '$lbl2' => t('Your password has been reset as requested.'),
80 '$lbl3' => t('Your new password is'),
81 '$lbl4' => t('Save or copy your new password - and then'),
82 '$lbl5' => '<a href="' . $a->get_baseurl() . '">' . t('click here to login') . '</a>.',
83 '$lbl6' => t('Your password may be changed from the <em>Settings</em> page after successful login.'),
84 '$newpass' => $new_password,
85 '$baseurl' => $a->get_baseurl()
88 notice("Your password has been reset." . EOL);
92 $email_tpl = load_view_file("view/passchanged_eml.tpl");
93 $email_tpl = replace_macros($email_tpl, array(
94 '$sitename' => $a->config['sitename'],
95 '$siteurl' => $a->get_baseurl(),
96 '$username' => $username,
98 '$new_password' => $new_password,
101 $res = mail($email,"Your password has changed at {$a->config['sitename']}",$email_tpl,
102 'From: ' . t('Administrator') . '@' . $_SERVER['SERVER_NAME'] . "\n"
103 . 'Content-type: text/plain; charset=UTF-8' . "\n"
104 . 'Content-transfer-encoding: 8bit' );
111 $tpl = load_view_file('view/lostpass.tpl');
113 $o .= replace_macros($tpl,array(
114 '$title' => t('Forgot your Password?'),
115 '$desc' => t('Enter your email address and submit to have your password reset. Then check your email for further instructions.'),
116 '$name' => t('Nickname or Email: '),
117 '$submit' => t('Reset')