Problem with login/hash on upgrading vom 1.1


I’m currently trying to update my app from yii1 to yii2, and I have a problem with the login. My passwords in yii1 are hashed and salted with ‘$2y$13$’. How can I validate my passwords on login?

public function validatePassword($password)


        if (Yii::$app->getSecurity()->validatePassword($password, '$2y$13$')) {

			return true;

		} else {

			return false;



This is wrong, “Hash is invalid.”, but I didn’t find any example how do do it, can anybody help, please?


You are giving the wrong hash (see this line).

You need to pass the whole hashed password as second argument (i.e. $2y$13$N0a5jjR2GSyEYHTgMEwiJ.JQOKYifQ0H3y8FxUFQKYuQN0KmsDPva).

Yeah, thanks, I changed it to

if (Yii::$app->getSecurity()->validatePassword($password, $this->password)) {

and now it works! I thought it was more complicated :D