3 * @file mod/lostpass.php
6 use Friendica\Core\System;
7 use Friendica\Database\DBM;
9 require_once 'include/enotify.php';
10 require_once 'include/text.php';
12 function lostpass_post(App $a) {
14 $loginame = notags(trim($_POST['login-name']));
16 goaway(System::baseUrl());
18 $r = q("SELECT * FROM `user` WHERE ( `email` = '%s' OR `nickname` = '%s' ) AND `verified` = 1 AND `blocked` = 0 LIMIT 1",
23 if (! DBM::is_result($r)) {
24 notice( t('No valid account found.') . EOL);
25 goaway(System::baseUrl());
29 $username = $r[0]['username'];
30 $email = $r[0]['email'];
32 $new_password = autoname(12) . mt_rand(100,9999);
33 $new_password_encoded = hash('whirlpool',$new_password);
35 $r = q("UPDATE `user` SET `pwdreset` = '%s' WHERE `uid` = %d",
36 dbesc($new_password_encoded),
40 info( t('Password reset request issued. Check your email.') . EOL);
43 $sitename = $a->config['sitename'];
44 $resetlink = System::baseUrl() . '/lostpass?verify=' . $new_password;
46 $preamble = deindent(t('
48 A request was recently received at "%2$s" to reset your account
49 password. In order to confirm this request, please select the verification link
50 below or paste it into your web browser address bar.
52 If you did NOT request this change, please DO NOT follow the link
53 provided and ignore and/or delete this email.
55 Your password will not be changed unless we can verify that you
56 issued this request.'));
58 Follow this link to verify your identity:
62 You will then receive a follow-up message containing the new password.
63 You may change that password from your account settings page after logging in.
65 The login details are as follows:
70 $preamble = sprintf($preamble, $username, $sitename);
71 $body = sprintf($body, $resetlink, System::baseUrl(), $email);
74 'type' => SYSTEM_EMAIL,
76 'subject'=> sprintf( t('Password reset requested at %s'),$sitename),
77 'preamble'=> $preamble,
80 goaway(System::baseUrl());
85 function lostpass_content(App $a) {
88 if(x($_GET,'verify')) {
89 $verify = $_GET['verify'];
90 $hash = hash('whirlpool', $verify);
92 $r = q("SELECT * FROM `user` WHERE `pwdreset` = '%s' LIMIT 1",
95 if (! DBM::is_result($r)) {
96 $o = t("Request could not be verified. \x28You may have previously submitted it.\x29 Password reset failed.");
100 $username = $r[0]['username'];
101 $email = $r[0]['email'];
103 $new_password = autoname(6) . mt_rand(100,9999);
104 $new_password_encoded = hash('whirlpool',$new_password);
106 $r = q("UPDATE `user` SET `password` = '%s', `pwdreset` = '' WHERE `uid` = %d",
107 dbesc($new_password_encoded),
111 /// @TODO Is DBM::is_result() okay here?
113 $tpl = get_markup_template('pwdreset.tpl');
114 $o .= replace_macros($tpl,array(
115 '$lbl1' => t('Password Reset'),
116 '$lbl2' => t('Your password has been reset as requested.'),
117 '$lbl3' => t('Your new password is'),
118 '$lbl4' => t('Save or copy your new password - and then'),
119 '$lbl5' => '<a href="' . System::baseUrl() . '">' . t('click here to login') . '</a>.',
120 '$lbl6' => t('Your password may be changed from the <em>Settings</em> page after successful login.'),
121 '$newpass' => $new_password,
122 '$baseurl' => System::baseUrl()
125 info("Your password has been reset." . EOL);
128 $sitename = $a->config['sitename'];
129 // $username, $email, $new_password
130 $preamble = deindent(t('
132 Your password has been changed as requested. Please retain this
133 information for your records (or change your password immediately to
134 something that you will remember).
137 Your login details are as follows:
143 You may change that password from your account settings page after logging in.
146 $preamble = sprintf($preamble, $username);
147 $body = sprintf($body, System::baseUrl(), $email, $new_password);
150 'type' => SYSTEM_EMAIL,
151 'to_email' => $email,
152 'subject'=> sprintf( t('Your password has been changed at %s'),$sitename),
153 'preamble'=> $preamble,
161 $tpl = get_markup_template('lostpass.tpl');
163 $o .= replace_macros($tpl,array(
164 '$title' => t('Forgot your Password?'),
165 '$desc' => t('Enter your email address and submit to have your password reset. Then check your email for further instructions.'),
166 '$name' => t('Nickname or Email: '),
167 '$submit' => t('Reset')