sexta-feira, dezembro 11, 2015

Script to reset all customer passwords in Magento

Script to reset all customer passwords in Magento




Script to reset all customer passwords in Magento


The following script was created to reset all customer passwords in a Magento store. It creates the new password from the first 3 characters of the customer’s current e-mail address, and a random 3 digit number. The total password length is 6 characters, but it can easily be modified. It also stores all the passwords to a tab-delimited file, this way you can refer to it later. All of this is just subjective, so you will want to tailor it to suit your exact needs.

For obvious security reasons, you will want to remove this script after you use it, or at the very least put it in a protected directory of some kind.
<?php
/************************ * / '_ __/_ _/_
* ()()/(-( /( ()(/(-
* _/
* since 2007
*
* Created by Foundco
* All rights reserved unless otherwise specified under contract.
* http://www.foundco.com/
* @author Christopher Hogan <mailing address removed>
* @copyright 2012 and beyond.
******************************/


error_reporting(E_ALL | E_STRICT);
$mageFilename = 'app/Mage.php';
if (!file_exists($mageFilename)) {
echo $mageFilename." was not found";
exit;
}
require_once $mageFilename;
Varien_Profiler::enable();
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app();

$passwordLength = 10;

/****
If you are just resetting one customer by customer_id:
****/

//$customer_id = 10;
//$customers = Mage::getModel('customer/customer')->getCollection()->addAttributeToFilter('entity_id', array('eq' => $customer_id));

/****
If you are resetting all customers:
****/

$customer_id = 10;
$customers = Mage::getModel('customer/customer')->getCollection();

/****
Now loop through the customers and create the passwords
****/

foreach ($customers as $customer){
// $customer->generatePassword($passwordLength)
// $customer->sendNewAccountEmail();
$password = strtoupper(substr( $customer->getEmail(), 0, 3)).rand(111,999);
$customer->setPassword($password)->save();
$line_data = $customer->getEmail(). "\t". $customer->getPassword();
$line[] = $line_data;
echo $line_data."\n";
}
$content = implode("\n", $line);

// store all the passwords to a file:
file_put_contents('./accounts.csv', $content);
echo "COMPLETE!";
?>

Nenhum comentário: