I have a string variable, and i want to check if this string variable match with the current customer password, is there a way to do this?

1 Answer 1


Please check this model


In this You will find one method authenticate($customerId, $password)

    public function authenticate($customerId, $password)
        $customerSecure = $this->customerRegistry->retrieveSecureData($customerId);
        $hash = $customerSecure->getPasswordHash();
        if (!$this->encryptor->validateHash($password, $hash)) {
            if ($this->isLocked($customerId)) {
                throw new UserLockedException(__('The account is locked.'));
            throw new InvalidEmailOrPasswordException(__('Invalid login or password.'));
        return true;

You can call this method and pass $customerId, and Password string. If password will be correct then it will return true. Otherwise it will throw an exception.

  • when i tried to use that function and insert wrong password, it won't redirect me to normal page instead i got exception page error Commented Feb 15, 2018 at 5:00
  • Yes because you see in above code it is throwing an exception. You just need to catch that exception so you will not get any error page Try to add TRY and Catch so you will not get error page. Commented Feb 15, 2018 at 5:09
  • i already wrap when calling the function using try&catch, but still it gives an error exception page Commented Feb 15, 2018 at 6:10
  • @IdhamChoudry I have need same thing. need to compare new password with exist password. have you get the solution ? Commented Oct 7, 2020 at 9:36

Your Answer

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

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