Menu Close
    Searching for an experienced Magento Development Company ?

    How to Match Customer Password in Magento 2

    In this blog, we will see how can we check if customer password is a match.
    We can use the below code to check this,

    $objectManager = \Magento\Framework\App\ObjectManager::getInstance();
    $customerAccountManagement = $objectManager->get('Magento\Customer\Api\AccountManagementInterface');
    try {
        $customer = $customerAccountManagement->authenticate($email, $password);
    } catch (\Exception $e) {
        //Authentication Failed
    }

    We can use Magento\Customer\Api\AccountManagementInterface and call the authenticate method which requires two parameters. First param is Email ID of the customer and the second param is the Password. It will return customer data model if it matches otherwise it will throw exception. So we have to write it in try-catch block.

    If you are looking for a way to change customer password programmatically then check out our blog “Change Customer Password Programmatically in Magento2

    Please comment if you face any issue or if there is any confusion. Thanks for checking out the blog.

    P.S. Please do not use Object Manager.

    . . .
    Discuss on Helpdesk

    Leave a Comment

    Your email address will not be published. Required fields are marked*


    Be the first to comment.

    Back to Top