10

I'm looking for a way to hook into the event of customers changing their passwords. So if someone changes the password in the customer frontend, I'd like to send an e-mail somewhere.

I did consult the list over at http://www.nicksays.co.uk/magento-events-cheat-sheet-1-7/ but nothing looks like an event for changing passwords.

1
  • Any idea what observer/event to use when a customer resets his password using /customer/account/resetpassword/?id=ab&token=xyz?
    – oschloebe
    Sep 17, 2013 at 12:20

3 Answers 3

9

Thanks to Fabian Blechschmidt, I came up with the following that works for me (using the event customer_save_before):

public function detectPwdChange(Varien_Event_Observer $observer) {
    $event              = $observer->getEvent();
    $customer           = $event->getCustomer();
    $postData           = Mage::app()->getRequest()->getPost();

    if($customer instanceof Mage_Customer_Model_Customer && !$customer->isObjectNew()) {

        if( $postData['change_password'] == 1 && $postData['current_password'] != $postData['password'] ) {
            // Do something
        }
    }

    return $this;
}
5
  • I don't like the request on the post, but if it works, great :-) Aug 23, 2013 at 9:45
  • It does work, yep. :-) I tried several methods und helper functions to get the password but all I was able to retreive was the password hash but I needed it plain readable and that's what the POST object offered. Thanks again!
    – oschloebe
    Aug 23, 2013 at 10:07
  • Don't do weird things with the password, like saving it in plaintext or bad crypto ;-) Aug 23, 2013 at 12:29
  • 1
    I won't, promised! Just sending it to PRISM. ;-)
    – oschloebe
    Aug 23, 2013 at 13:00
  • this doesnt work as is for reset password as there is only password and confirmationin post data. tested with v1.9
    – pHiL
    May 16, 2016 at 20:59
5

Have a look into the code.

You can use the customer_save_after event and just check for

/app/code/core/Mage/Customer/controllers/AccountController.php:724
$customer->setChangePassword(1);

Maybe this value is reseted, then you have to use save_before, but I recommend to send the mail after the saving. So if this value is not readable in the after event, copy it to another attribute to have it by hand in the after event.

2
  • Thanks so far. As far as I can see the event is also triggered when a customer successfully registered. Is there a way/method I can check if the customer was registered already and the password actually changed?
    – oschloebe
    Aug 22, 2013 at 12:03
  • in the _before event you can check whether an ID already exists on the object Aug 22, 2013 at 12:34
4

I wanted to do something similar, but I ended up with his code instead:

I hooked onto controller_action_postdispatch_customer_account_resetpasswordpost

function resetpasswordpost(Varien_Event_Observer $observer) {
    $customer_id = Mage::app()->getRequest()->getParam('id');
    $customer = Mage::getModel('customer/customer')->load($customer_id);
}

A bit more cleaner and "safer" than faffing about with the Password itself, I think!

1
  • Mage::app()->getRequest()->getParam('id') is null in this event. also in predispatch. password and confirmation is available in Mage::app()->getRequest()->getParams() tho. (Tested with v1.9)
    – pHiL
    May 16, 2016 at 18:11

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.