3 require_once('include/email.php');
5 function lostpass_post(&$a) {
7 $loginame = notags(trim($_POST['login-name']));
11 $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) AND `verified` = 1 AND `blocked` = 0 LIMIT 1",
17 notice( t('No valid account found.') . EOL);
22 $username = $r[0]['username'];
23 $email = $r[0]['email'];
25 $new_password = autoname(12) . mt_rand(100,9999);
26 $new_password_encoded = hash('whirlpool',$new_password);
28 $r = q("UPDATE `user` SET `pwdreset` = '%s' WHERE `uid` = %d",
29 dbesc($new_password_encoded),
33 info( t('Password reset request issued. Check your email.') . EOL);
35 $email_tpl = get_intltext_template("lostpass_eml.tpl");
36 $email_tpl = replace_macros($email_tpl, array(
37 '$sitename' => $a->config['sitename'],
38 '$siteurl' => $a->get_baseurl(),
39 '$username' => $username,
41 '$reset_link' => $a->get_baseurl() . '/lostpass?verify=' . $new_password
44 $res = mail($email, email_header_encode(sprintf( t('Password reset requested at %s'),$a->config['sitename']),'UTF-8'),
46 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
47 . 'Content-type: text/plain; charset=UTF-8' . "\n"
48 . 'Content-transfer-encoding: 8bit' );
55 function lostpass_content(&$a) {
58 if(x($_GET,'verify')) {
59 $verify = $_GET['verify'];
60 $hash = hash('whirlpool', $verify);
62 $r = q("SELECT * FROM `user` WHERE `pwdreset` = '%s' LIMIT 1",
66 notice( t("Request could not be verified. \x28You may have previously submitted it.\x29 Password reset failed.") . EOL);
71 $username = $r[0]['username'];
72 $email = $r[0]['email'];
74 $new_password = autoname(6) . mt_rand(100,9999);
75 $new_password_encoded = hash('whirlpool',$new_password);
77 $r = q("UPDATE `user` SET `password` = '%s', `pwdreset` = '' WHERE `uid` = %d",
78 dbesc($new_password_encoded),
82 $tpl = get_markup_template('pwdreset.tpl');
83 $o .= replace_macros($tpl,array(
84 '$lbl1' => t('Password Reset'),
85 '$lbl2' => t('Your password has been reset as requested.'),
86 '$lbl3' => t('Your new password is'),
87 '$lbl4' => t('Save or copy your new password - and then'),
88 '$lbl5' => '<a href="' . $a->get_baseurl() . '">' . t('click here to login') . '</a>.',
89 '$lbl6' => t('Your password may be changed from the <em>Settings</em> page after successful login.'),
90 '$newpass' => $new_password,
91 '$baseurl' => $a->get_baseurl()
94 info("Your password has been reset." . EOL);
98 $email_tpl = get_intltext_template("passchanged_eml.tpl");
99 $email_tpl = replace_macros($email_tpl, array(
100 '$sitename' => $a->config['sitename'],
101 '$siteurl' => $a->get_baseurl(),
102 '$username' => $username,
104 '$new_password' => $new_password,
105 '$uid' => $newuid ));
107 $subject = sprintf( t('Your password has been changed at %s'), $a->config['sitename']);
109 $res = mail($email, email_header_encode( $subject, 'UTF-8'), $email_tpl,
110 'From: ' . 'Administrator' . '@' . $_SERVER['SERVER_NAME'] . "\n"
111 . 'Content-type: text/plain; charset=UTF-8' . "\n"
112 . 'Content-transfer-encoding: 8bit' );
119 $tpl = get_markup_template('lostpass.tpl');
121 $o .= replace_macros($tpl,array(
122 '$title' => t('Forgot your Password?'),
123 '$desc' => t('Enter your email address and submit to have your password reset. Then check your email for further instructions.'),
124 '$name' => t('Nickname or Email: '),
125 '$submit' => t('Reset')