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']),
39 $email_tpl, 'From: ' . t('Administrator') . '@' . $_SERVER[SERVER_NAME]);
41 goaway($a->get_baseurl());
45 function lostpass_content(&$a) {
48 if(x($_GET,'verify')) {
49 $verify = $_GET['verify'];
50 $hash = hash('whirlpool', $verify);
52 $r = q("SELECT * FROM `user` WHERE `pwdreset` = '%s' LIMIT 1",
56 notice( t("Request could not be verified. \x28You may have previously submitted it.\x29 Password reset failed.") . EOL);
57 goaway($a->get_baseurl());
61 $username = $r[0]['username'];
62 $email = $r[0]['email'];
64 $new_password = autoname(6) . mt_rand(100,9999);
65 $new_password_encoded = hash('whirlpool',$new_password);
67 $r = q("UPDATE `user` SET `password` = '%s', `pwdreset` = '' WHERE `uid` = %d LIMIT 1",
68 dbesc($new_password_encoded),
72 $tpl = load_view_file('view/pwdreset.tpl');
73 $o .= replace_macros($tpl,array(
74 '$lbl1' => t('Password Reset'),
75 '$lbl2' => t('Your password has been reset as requested.'),
76 '$lbl3' => t('Your new password is'),
77 '$lbl4' => t('Save or copy your new password - and then'),
78 '$lbl5' => '<a href="' . $a->get_baseurl() . '">' . t('click here to login') . '</a>.',
79 '$lbl6' => t('Your password may be changed from the <em>Settings</em> page after successful login.'),
80 '$newpass' => $new_password,
81 '$baseurl' => $a->get_baseurl()
84 notice("Your password has been reset." . EOL);
88 $email_tpl = load_view_file("view/passchanged_eml.tpl");
89 $email_tpl = replace_macros($email_tpl, array(
90 '$sitename' => $a->config['sitename'],
91 '$siteurl' => $a->get_baseurl(),
92 '$username' => $username,
94 '$new_password' => $new_password,
97 $res = mail($email,"Your password has changed at {$a->config['sitename']}",$email_tpl,"From: Administrator@{$_SERVER[SERVER_NAME]}");
104 $tpl = load_view_file('view/lostpass.tpl');
106 $o .= replace_macros($tpl,array(
107 '$title' => t('Forgot your Password?'),
108 '$desc' => t('Enter your email address and submit to have your password reset. Then check your email for further instructions.'),
109 '$name' => t('Nickname or Email: '),
110 '$submit' => t('Reset')