我想在Magento
更改客户的登录密码,我使用以下代码更新密码但它对我不起作用
$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();
}
答案 0 :(得分:8)
使用以下代码更新用户密码,您需要更新用户名和storeid附加变量。 : -
$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;
答案 1 :(得分:3)
如果你回显$ completeOldPassword和$ passwordhash,你会发现它们无法匹配,因为你的$ oldpassword应该是一个带盐的密码哈希。现在它只是明文
如果您只想更改密码而不检查旧密码,请尝试以下
$customerid = 46;
$newpassword = 87654321;
$customer = Mage::getModel('customer/customer')->load($customerid);
$customer->setPassword($newpassword);
$customer->save();
答案 2 :(得分:0)
唯一的解决方案是使用忘记密码并使用电子邮件帐户重置密码.Magento在密码中添加安全盐哈希值,你不能像你那样改变它。
答案 3 :(得分:0)
允许更改customer.update API请求的密码
使用password_hash作为发送请求的属性名称, 并在更新的功能 $ MAGENTO_ROOT / app / code / core / Mage / Customer / Model / Customer / Api.php add
<$>之前$ customer-&gt; save();if(strlen($ customerData [“password_hash”])&gt; 5){
$客户 - &GT; setPassword($ customerData [ “password_hash”]);
}
忘记http://www.magentocommerce.com/api/soap/customer/customer.update.html
中提到的密码属性只有password_hash是客户实体的有效属性。