Categories: How To

How to Generate & Email New Password Programmatically to Customers in Magento

Working with clients in Magento brings numerous challanges and recently one of our clients came up with such an issue where his customer accounts got hacked and he wanted us to generate new passwords and Email them to customers from his Magento store.

Unfortunately Magento stores get hacked sometime due to reasons such as installation of buggy Magento extensions, using an outdated version or many more you even don’t know the reason behind. In our case, Using Magento functions, this has to be done programmatically to save the hassle of doing it manually for each user. All we require is to create a custom code to generate new passwords for all registered users and send them in Email programmatically.

Use following code to Generate & Email New Password Programmatically to Customers in Magento

<?php ini_set('display_errors',true); include 'app/Mage.php'; Mage::setIsDeveloperMode(true); Mage::app(); try { $collection = Mage::getResourceModel('customer/customer_collection'); /* Group Filter For particulor Group of customer */ /* $collection->addFieldToFilter('group_id',4); */ foreach ($collection as $customer) {
  $customer->setForceConfirmed(true);
  $sendPassToEmail = true;
  $customer->setPassword($customer->generatePassword());
  $customer->save();
  $customer->sendNewAccountEmail('registered', '', $customer->getStoreId());
  echo "Email :".$customer->getEmail();
 }
}
catch(Exception $e)
{
 Mage::log($e->getMessage(),null,"resetpasswd.log",true);
}

Voila, implementing the above code, passwords would be instantaneously generated and Emailed to the desired customers. Now you are having a much faster solution to apply password changes for large scale customers. Let me know if you have any questions through commenting. Also your suggestions and feedback are always welcomed.

Click to rate this post!
[Total: 2 Average: 5]
Dhiren Vasoya

Dhiren Vasoya is a Director and Co-founder at MageComp, Passionate 🎖️ Certified Magento Developer👨‍💻. He has more than 9 years of experience in Magento Development and completed 850+ projects to solve the most important E-commerce challenges. He is fond❤️ of coding and if he is not busy developing then you can find him at the cricket ground, hitting boundaries.🏏

Recent Posts

What are Net Sales? How to Calculate Your Net Sales?

In the world of business, understanding financial metrics is crucial for making informed decisions and…

16 hours ago

Magento 2 Extensions Digest April 2024 (New Release & Updates)

Welcome to the MageComp Monthly Digest, where we bring you the latest updates, releases, and…

16 hours ago

The ABCs of Geofencing: Definition, Features and Uses

In this era, businesses are always on the lookout for ways to engage with their…

2 days ago

How to Delete Product Variant in a Shopify Remix App using GraphQL Mutations?

Managing a Shopify store efficiently involves keeping your product catalog organized. This includes removing outdated…

2 days ago

6 Innovative Tools Revolutionizing E-Commerce Operations

E-commerce has transformed the way consumers shop for products and services and interact with businesses.…

5 days ago

How Upcoming Cookie Changes Will Affect Your E-commerce Website?

The e-commerce world is constantly in flux. New tech and strategies emerge daily to help…

5 days ago