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("Password reset request issued. Check your email.");
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, t('Password reset requested at ') . $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("Request could not be verified. (You may have previously submitted it.) 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 '$newpass' => $new_password,
75 '$baseurl' => $a->get_baseurl()
77 notice("Your password has been reset." . EOL);
81 $email_tpl = load_view_file("view/passchanged_eml.tpl");
82 $email_tpl = replace_macros($email_tpl, array(
83 '$sitename' => $a->config['sitename'],
84 '$siteurl' => $a->get_baseurl(),
85 '$username' => $username,
87 '$new_password' => $new_password,
90 $res = mail($email,"Your password has changed at {$a->config['sitename']}",$email_tpl,"From: Administrator@{$_SERVER[SERVER_NAME]}");
97 $tpl = load_view_file('view/lostpass.tpl');