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();
唯一的解决方案是使用忘记密码并使用电子邮件帐户重置密码.Magento在密码中添加安全盐哈希值,您无法像您所做的那样更改密码。
To allow change password for customer.update API request
Use password_hash as the attribute name to send the request, and in update function of $MAGENTO_ROOT/app/code/core/Mage/Customer/Model/Customer/Api.php add
if(strlen($customerData["password_hash"]) > 5){
$customer->setPassword($customerData["password_hash"]);
}
before $customer->save();
Forget the password attribute mentioned in http://www.magentocommerce.com/api/soap/customer/customer.update.html
only password_hash is a valid attribute for customer entity.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.