Yii2 Exception in ValidatePassword()

允我心安 提交于 2019-12-13 00:47:09

问题


I use yii2 for developing web site.
Before save user to db, I encripted password like this:

$this->password = Yii::$app->security->generatePasswordHash($this->password);

And when I use this code:

Yii::$app->security->validatePassword("some string", $this->password);

I have error:

Invalid Parameter – yii\base\InvalidParamException Hash is invalid.

What is wrong?


回答1:


I ran into the same issue. I realized that my password field's character capacity was too short for the hash, so I bumped it up from varchar(25) to varchar(255).




回答2:


make sureyou have a column name exactly as password_hash in the user table and change your code from

Yii::$app->security->validatePassword("some string", $this->password);

to:

Yii::$app->security->validatePassword("some string", $this->password_hash);



来源:https://stackoverflow.com/questions/25910302/yii2-exception-in-validatepassword

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!