I want to Change Login Password of a customer in Magento
, I Uses the below Code to Update the Password But It doesn't work for me
$customerid = 46;
$oldpassword = 12345678;
$newpassword = 87654321;
$customer = Mage::getModel('customer/customer')->load($customerid);
$passwordhash = $customer['password_hash'];
$phasharray = explode(":",$passwordhash);
$passpostfix = $phasharray[1];
$completeOldPassword = $oldpassword.":".$passpostfix;
if($completeOldPassword==$passwordhash){
$customer->setPassword($newpassword);
$customer->save();
}
Use below code to update user's password, you need username and storeid additional variable to update. :-
$validate = 0; $result = '';
$customerid = 46;
$username = 'YOUR_USERNAME';
$oldpassword = 12345678;
$newpassword = 87654321;
$storeid = 'YOUR_STORE_ID';
$websiteId = Mage::getModel('core/store')->load($storeid)->getWebsiteId();
try {
$login_customer_result = Mage::getModel('customer/customer')->setWebsiteId($websiteId)->authenticate($username, $oldpassword);
$validate = 1;
}
catch(Exception $ex) {
$validate = 0;
}
if($validate == 1) {
try {
$customer = Mage::getModel('customer/customer')->load($customerid);
$customer->setPassword($newpassword);
$customer->save();
$result = 'Your Password has been Changed Successfully';
}
catch(Exception $ex) {
$result = 'Error : '.$ex->getMessage();
}
}
else {
$result = 'Incorrect Old Password.';
}
echo $result;
If you echo $completeOldPassword and $passwordhash you see they can't match because your $oldpassword is supposed to be a password hash with salt. Now it's just plaintext
If you only want to change the password without checking old password try this
$customerid = 46;
$newpassword = 87654321;
$customer = Mage::getModel('customer/customer')->load($customerid);
$customer->setPassword($newpassword);
$customer->save();
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With