【发布时间】:2016-02-10 20:00:53
【问题描述】:
当您从 ActiveRecord 扩展您的类时,您是否使用过用户数据?我想更新用户时遇到问题。有 PasswordHash 属性。我在创建时使用了 beforeSave 函数,但我不知道我应该在更新操作中使用它吗?
public function beforeSave($insert)
{
if (parent::beforeSave($insert)) {
if($this->isNewRecord) {
$this->created_at = time();
$this->status = self::DEFAULT_STATUS;
$this->generateAuthKey();
$this->setPassword($this->PasswordHash);
$this->RulesAccept=1;
return true;
} else {
$this->setPassword($this->PasswordHash);
return true;
}
}
}
当我在输入中更新用户时,我可以看到散列密码,但是当我更改密码时,它没有散列这个密码。我修改了我的代码,但密码不断被覆盖。我应该如何在 ActiveRecord 中使用 passwordInput 和密码散列?
【问题讨论】:
标签: php activerecord hash passwords yii2