<![CDATA[ Forgot Password not resetting the password - My Forums]]> https://forums.modx.com/thread/?thread=90993 <![CDATA[Re: Forgot Password not resetting the password]]> https://forums.modx.com/thread/90993/forgot-password-not-resetting-the-password#dis-post-563511
I have to admit I am impressed by the amount of effort I went to in recording this issue, but I cannot remember anything about it that is not written above. I don't use MODx very much now. I spent so much of my life trying to solve problems such as this, with often unclear documentation or little response here in the forum, that I got a bit burned out with it.

Good luck!]]>
Gav Jan 10, 2019, 12:28 PM https://forums.modx.com/thread/90993/forgot-password-not-resetting-the-password#dis-post-563511
<![CDATA[Re: Forgot Password not resetting the password]]> https://forums.modx.com/thread/90993/forgot-password-not-resetting-the-password#dis-post-563506 jimmyjazz Jan 10, 2019, 02:45 AM https://forums.modx.com/thread/90993/forgot-password-not-resetting-the-password#dis-post-563506 <![CDATA[Re: Forgot Password not resetting the password]]> https://forums.modx.com/thread/90993/forgot-password-not-resetting-the-password#dis-post-498798
I think also that I may have done initial tests in the same browser as I was logged into the Manager, which may have bypassed the unplublished status of the page :-(

So to answer my own question: The password is not actually changed in the db until the user clicks on the link in the email and the ResetPassword snippet is called.

For reference, the relevant docs are here:

http://rtfm.modx.com/extras/revo/login/login.forgotpassword

http://rtfm.modx.com/extras/revo/login/login.resetpassword

http://rtfm.modx.com/extras/revo/login/login.tutorials/login.basic-setup#Login.BasicSetup-ResetPasswordHandler%283%29]]>
Gav May 28, 2014, 06:16 AM https://forums.modx.com/thread/90993/forgot-password-not-resetting-the-password#dis-post-498798
<![CDATA[Re: Forgot Password not resetting the password]]> https://forums.modx.com/thread/90993/forgot-password-not-resetting-the-password#dis-post-498738
In /core/components/login/controllers/web/ForgotPassword.php there's a sendPasswordResetEmail() function:
    /**
     * Send an email to the user with a confirmation URL to reset their password at
     * @return void
     */
    public function sendPasswordResetEmail() {
        $fields = $this->dictionary->toArray();
        
        /* generate a password and encode it and the username into the url */
        $password = $this->login->generatePassword();
        $confirmParams = array(
            'lp' => urlencode(base64_encode($password)),
            'lu' => urlencode(base64_encode($fields['username']))
        );
        $confirmUrl = $this->modx->makeUrl($this->getProperty('resetResourceId',1),'',$confirmParams,'full');

        /* set the email properties */
        $emailProperties = $fields;
        $emailProperties['confirmUrl'] = $confirmUrl;
        $emailProperties['password'] = $password;
        $emailProperties['tpl'] = $this->getProperty('emailTpl');
        $emailProperties['tplAlt'] = $this->getProperty('emailTplAlt','');
        $emailProperties['tplType'] = $this->getProperty('emailTplType');

        /* now set new password to cache to prevent middleman attacks */
        $this->modx->cacheManager->set('login/resetpassword/'.$fields['username'],$password);

        $emailSubject = $this->getProperty('emailSubject','');
        $subject = !empty($emailSubject) ? $emailSubject : 
                $this->modx->getOption('login.forgot_password_email_subject',
                                        null,
                                        $this->modx->lexicon('login.forgot_password_email_subject'));
        $this->login->sendEmail($fields['email'],$fields['username'],$subject,$emailProperties);
        $this->emailsSent++;
    }
(I've wrapped line 28 to avoid horiz scrolling)

This all seems to look ok to me. If I clear the entire cache dir, then run through the forgot password procedure in my site, I get the following email:
myusername,
To activate your new password, please click on the following link:
http://mydomain.co.uk/subdir/index.php?id=8&lp=cjB6YnZxNGQ%253P&lu=YW5kZXJzb24tcGhhcm0%253P
If successful you can use the following password to login:
Password: r0zbvr4d
If you did not request this message, please ignore it.
Thanks,
Site Administrator
and in the cache dir I now see the file: /core/cache/default/login/resetpassword/myusername.cache.php, with the following content:
<?php return 'r0zbvq4d';

But I cannot see where the password is saved to the db. Should it be done before the email is sent out, or is it done only when the user clicks the link in the email?]]>
Gav May 27, 2014, 10:13 AM https://forums.modx.com/thread/90993/forgot-password-not-resetting-the-password#dis-post-498738
<![CDATA[Re: Forgot Password not resetting the password]]> https://forums.modx.com/thread/90993/forgot-password-not-resetting-the-password#dis-post-498702 ]]> Gav May 27, 2014, 04:00 AM https://forums.modx.com/thread/90993/forgot-password-not-resetting-the-password#dis-post-498702 <![CDATA[Re: Forgot Password not resetting the password]]> https://forums.modx.com/thread/90993/forgot-password-not-resetting-the-password#dis-post-498416 Gav May 22, 2014, 03:15 AM https://forums.modx.com/thread/90993/forgot-password-not-resetting-the-password#dis-post-498416 <![CDATA[Forgot Password not resetting the password]]> https://forums.modx.com/thread/90993/forgot-password-not-resetting-the-password#dis-post-498323
I have the Login snippet set up according to the docs and all seems to run ok, except for the Forgot Password.

Here are the snippet calls in my pages:

The Forgot Password page (id 7):
[[!ForgotPassword? &resetResourceId=`8` &tpl=`lgnForgotPassTpl`]]

Reset Password Handler page (id 8 ):
[[!ResetPassword? &loginResourceId=`6`]]

Login page (id 6);
[[!Login? &loginTpl=`lgnLoginTpl2`
&logoutTpl=`lgnLogoutTpl`
&errTpl=`lgnErrTpl`
&loginResourceId=`9`
&postHooks=`userLandingPage`
&logoutResourceId=`6`
&logoutMsg=`Goodbye!`
]]

The password reset email arrives at the correct address and looks like:
theusername,

To activate your new password, please click on the following link:

http://mydomain/index.php?id=8&lp=NzYxcHdxc2Y%253D&lu=YW5kZXJzb24tcGhhcm0%253D

If successful you can use the following password to login:

Password: 761pwqsf


If you did not request this message, please ignore it.

Thanks,
Site Administrator
(Note the link here is to the handler, not the login page. Is this correct?)

If I click on the link I arrive at the default (Home) page. I click through to the login page (id 6) and try to login with the new password, but it fails with the following message:
The username or password you entered is incorrect. Please check the username, re-type the password, and try again.

I had a look in my database before and after password resets and nothing appears to change (modx_users table). (The original password still works and I can login with that, so def no change in the db).

In my error log, the only entries which may be related to this issue are:
[2014-05-21 09:19:29] (INFO @ /mydomain/index.php) Principal 0 does not have permission to load object of class modDocument with primary key: 9
[2014-05-21 09:19:29] (INFO @ /mydomain/index.php) Principal 0 does not have permission to load object of class modDocument with primary key: 25
[2014-05-21 09:19:29] (INFO @ /mydomain/index.php) Principal 0 does not have permission to load object of class modDocument with primary key: 26
[2014-05-21 09:19:29] (INFO @ /mydomain/index.php) Principal 0 does not have permission to load object of class modDocument with primary key: 5
[2014-05-21 09:19:29] (INFO @ /mydomain/index.php) Principal 0 does not have permission to load object of class modDocument with primary key: 5
(The id of the user is 5, in the modx_users table. Nor sure where the ids 25 and 26 apply to)

I see that there was a bug related to this issue reported back in (http://bugs.modx.com/issues/6658), although my error messages are different, but there is no indication as to whether it has been worked on or fixed.

Any suggestions as to a cause and cure to make my passwords reset?]]>
Gav May 21, 2014, 04:12 AM https://forums.modx.com/thread/90993/forgot-password-not-resetting-the-password#dis-post-498323