Magento – Update customer password using custom php script and CSV file

Home / Magento / Magento – Update customer password using custom php script and CSV file

Please follow below steps to update customer password using custom php script and CSV file, please take db backup for safety.

Step 1: Created update_customer_password.php file in root of your magento project Paste Below Code in update_customer_password.php file

<?php
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app('admin');
Mage::register('isSecureArea', 1);
Mage::app()->setCurrentStore(Mage_Core_Model_App::ADMIN_STORE_ID);
?>
<?php

$storagename = "customers.csv";

if(($handle = fopen("var/".$storagename, 'r')) !== FALSE) {

set_time_limit(0);
$row = 0;
$i=0;
while(($data = fgetcsv($handle, 0, ',')) !== FALSE) {
$num = count($data);
if($i!=0)
{
$csv[$row]['customers_email_address'] = $data[0];
$csv[$row]['customers_password'] = $data[1];

$row++;
}
$i++;
}
fclose($handle);
}

foreach($csv as $cust)
{

$customer = Mage::getModel('customer/customer');
$customer->setWebsiteId(1);

$customer->loadByEmail(strtolower($cust['customers_email_address']));

$customerid=$customer->getId();
if($customerid>0)
{
$write = Mage::getSingleton('core/resource')->getConnection('core_write');
$password = $cust['customers_password'];
$customerid=$customer->getId();
$write->query("update customer_entity_varchar set value='$password' where entity_id='$customerid' and attribute_id=12");
echo $cust['customers_email_address'].' ..................<b>Password Updated</b> <br>';
}
else
{
echo $cust['customers_email_address'].' ..................<b>Email NOT FOUND</b> <br>';
}
}
?>

 

Step 2: Please find .csv file for SAMPLE CSV COPY and put it in VAR folder/directory.

Step 3: Execute .php file in browser and check password is updated or not.

Looking for theme / plugin support?

Looking for theme / plugin customization?