Magento 2 store owners tend to collect customers’ data for various purposes such as marketing, understanding customers’ behaviour and shopping pattern, or simply offer a better user experience.
Apart from collecting customers’ data is to collect their Email ID while registering with Magento 2 store. Every store owner usually confirms if the given Email ID is correct or not.
However, when you programmatically login customer without a password, in that case even if the email is not confirmed, the customer can log in. In this situation, you need to programmatically check if customer account is confirmed or not in Magento 2.
The below code is the method for the same:
Method to Programmatically Check if Customer Account is Confirmed or not in Magento 2
Use the below code in the helper file.
class Data extends AbstractHelper
public function __construct(
$this->accountManagement = $accountManagement;
public function isAccountConfirmed($customerId)
isAccountConfirmed() function returns result as :
Use the above solution and stop the unauthenticated user in your store or else, you could just use the Magento 2 Restrict Fake Registration extension!
Any doubts about the topic can be mentioned in the Comments section below. I’d be happy to help.
Also, please share the tutorial with the Magento community via social media.
Get Weekly Updates
Never miss Magento tips, tricks, tutorials, and news.
Thank you for subscribing.
Something went wrong.