Magento 2 create customer programmatically without password

In this blog, We will discuss how to create a customer programmatically. How many ways to create a Magento 2 customer. We will discuss in both editions, Magento 2 enterprise edition and community edition. 

If I have a customer Id(email_id) and I want to login without a password. So, what is the step to open my account dashboard?

Let's discuss !!!

As per my opinion, We can use the below possible way.

1. Get a password in your mailId using "Forgot Your Password?" Link 

If I forgot the password, I can get the password using forgot password link. Click the sign-in link on the top-right header. After click on the forgot password link as per the below screenshot.

Magento 2 create customer programmatically without password

Now, Fill in the required information and reset your password. Reset Password link will come on your registered mail id. You can create a new password and after you can log in to your account.
Magento 2 create customer programmatically without password


2. Login Customer Account using External Script. 

We need to create one external script in Magento project root folder. I have created one external script "customer_login.php" as per the below screenshot.
Magento 2 create customer programmatically without password


Now, simply pest the below code on your external script and run it on your browser.
<?php
use Magento\Framework\App\Bootstrap;
 
require __DIR__ . '/app/bootstrap.php';
 
$params = $_SERVER;
 
$bootstrap = Bootstrap::create(BP, $params);
 
$object = $bootstrap->getObjectManager();
 
$statecall = $object->get('Magento\Framework\App\State');
$statecall->setAreaCode('frontend');
$websiteId = $object->get('Magento\Store\Model\StoreManagerInterface')->getStore()->getWebsiteId();
$customerObj = $object->get('Magento\Customer\Model\Customer')->setWebsiteId($websiteId)->loadByEmail("bhavesh@trycoder.com");
$customer = $object->get('Magento\Customer\Model\Session')->setCustomerAsLoggedIn($customerObj);
echo "done";
?>
I have run the script on my browser as per the below screenshot. It's successfully run without any errors.
Magento 2 create customer programmatically without password


Now, I log in automatically, without the required password As per the below screenshot.

Magento 2 create customer programmatically without password


Ask Question #trycoder
Facebook Page👉 https://bit.ly/3o688OF
Watch more videos here
Click to SUBSCRIBE to more Videos!

Please Like, Comment, Share and Subscribe THANK YOU!

0 Comments