以下确实有效:
// app/Controller/UsersController.php
$this->User->save(array('pwd'=>$new_pwd),false);
以下不起作用:
// app/Controller/UsersController.php
$this->User->setPassword($new_pwd);
该User
模型具有beforeSave()
有效的方法和无效的自定义方法setPassword()
:
// app/Model/User.php
public function beforeSave($options = array()) {
if (isset($this->data[$this->alias]['pwd'])&&!empty($this->data[$this->alias]['pwd'])) {
$new_password = $this->data[$this->alias]['pwd'];
$passwordHasher = new BlowfishPasswordHasher();
$this->data[$this->alias]['pwd'] = $passwordHasher->hash($new_password);
}
return true;
}
public function setPassword($new_password) {
$passwordHasher = new BlowfishPasswordHasher();
$result = $this->save(array(
'pwd' => $passwordHasher->hash($new_password),
), false);
return $result;
}
因此,setPassword()
当我尝试使用以这种方式保存的密码登录时,它或多或少是相同的,$this->Auth->login()
返回 false。我可以看到数据库中更新的密码哈希。
我错过了什么吗?请帮忙