1

In account page how to validate that the current password and new password are not the same?

2

To check, that the user changed his password, you need his old password - this is not possible, because it is hashed.

So the other way around, hash the new password:

use \Mage_Core_Model_Encryption::validateHash($password, $hash)

where $password is the new password and $hash is the old password.

If the exception is thrown, the password was changed.

public function validateHash($password, $hash)
{
    $hashArr = explode(':', $hash);
    switch (count($hashArr)) {
        case 1:
            return $this->hash($password) === $hash;
        case 2:
            return $this->hash($hashArr[1] . $password) === $hashArr[0];
    }
    Mage::throwException('Invalid hash.');
}
  • this code is Ok but I want to check whether current password and new password are same or not if same error message should display else password should change how to do this – vidhya Jan 16 '14 at 13:48
  • 1
    Yes, catch the exception, if it is thrown, the passwords differ, if nothing is catched, the passwords are the same – Fabian Blechschmidt Jan 16 '14 at 14:00
0

Use below code

<form .....>
......
<input type="password" class="validate-password" name="userpassword"/>
<input type="password" class="validate-cpassword" name="comparepassword"/>
....
</form>

Hope you understand this just use two classes validate-password and validate-cpassword

  • I think that checks if the values are the same. The OP wants the other way around. – Marius Jan 16 '14 at 13:13
  • yes @Marius I understand wrong. – Keyul Shah Jan 16 '14 at 13:16

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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