Magento 2 allows customers to log in from the store’s frontend, and the admin can also handle customers from the backend.
But, what if you want your customers to log in to the Magento 2 store using only the Email ID?
The below solution allows facilitating login customer programmatically without password in Magento 2.
You can use this login method if you offer Magento extensions and want to show the demo store where the users can directly log in without having to remember a password.
Also, if you are developing a login module using which the customer can log in with just a click or by only entering the Email ID, you may find this solution helpful.
In all these scenarios, offering an easy login where users can have quick access to the store only contributes to a better user experience and thus benefits your business!
Method to Login Customer Programmatically Without Password in Magento 2
Use the below code in your controller file.
public function __construct(
$this->session = $session;
$this->customerFactory = $customerFactory;
$customer = $this->customerFactory->create();
$loadCustomer = $customer->loadByEmail($email);
In the $email variable, enter the email id of the customer you want to log in.
If you have any doubts regarding this post, just mention them in the Comments section below.
I would be happy to help.
Feel free to share the solution with Magento Community via social media.
Get Weekly Updates
Never miss Magento tips, tricks, tutorials, and news.
Thank you for subscribing.
Something went wrong.