Magento2 – How to authenticate customer by email

Magento2 – How to authenticate customer by email

To authenticate customer using email and password, create an instance of \Magento\Customer\Api\AccountManagementInterface class and call authenticate(..) method. The authenticate method requires email and password parameters.

use Magento\Customer\Api\AccountManagementInterface;

private AccountManagementInterface $accountManagement;

public function __construct(AccountManagementInterface $accountManagement)
    $this->accountManagement = $accountManagement;


try {
    $customer = $this->accountManagement->authenticate("[email protected]", "example123#");
    echo "Welcome {$customer->getFirstname()} {$customer->getLastname()}";
} catch (\Magento\Framework\Exception\LocalizedException $e) {
    echo $e->getMessage();

How useful was this post?

Click on a star to rate it!

Average rating / 5. Vote count:

No votes so far! Be the first to rate this post.

As you found this post useful...

Follow us on social media!

We are sorry that this post was not useful for you!

Let us improve this post!

Tell us how we can improve this post?

Leave a Reply

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