Yii2 - 验证密码(哈希无效错误) [英] Yii2 - validate password (Hash is invalid error)

查看:44
本文介绍了Yii2 - 验证密码(哈希无效错误)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试验证旧用户密码,以便他能够更改密码,但目前我收到哈希无效错误.

I am trying to validate old user password, in order for him to able to change password, but at the moment I am getting Hash is invalid error.

这是验证规则:

['password_old', function($attribute){
                if(!$this->validatePassword($this->{$attribute}))
                    $this->addError($attribute, 'Please Enter Your Old Password');
            }],

validatePassword 方法:

    public function validatePassword($password){
            return Yii::$app->getSecurity()->validatePassword($this->salt . $password, $this->password);
        }

用于更改密码的表单:

$form = ActiveForm::begin(
            [
                'enableAjaxValidation' => true,
                'action'               => 'user/changepassword',
                'id'                   => 'changePassword'
            ]
        );


    echo $form->field($model, 'password_old')->passwordInput( ['autocomplete' => 'off'] );
    echo $form->field($model, 'password')->passwordInput(['autocomplete' => 'off'])->label('New Password');
    echo $form->field($model, 'password_confirm')->passwordInput(['autocomplete' => 'off']);  

推荐答案

我解决了这个问题,将 DB 中密码列的值从 varchar(128) 更改为 varchar(255) 并重新注册.

I'm solved the problem, when change value of password column in DB from varchar(128) to varchar(255) and registerd again.

这篇关于Yii2 - 验证密码(哈希无效错误)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆