Answer the question
In order to leave comments, you need to log in
Authentication problem with validatePassword()?
I can’t understand what’s wrong validatePassword() always raises an error regardless of whether the password is entered correctly or not, I do this in the Users model, I generate a password and save it to the database using the method
public function setPassword($password){
$this->password = Yii::$app->getSecurity()->generatePasswordHash($password);
}
public function validatePassword($attribute, $params)
{
if (!$this->hasErrors()) {
$user = $this->getUser();
if (!$user || !Yii::$app->security->validatePassword($this->password, $user->password)) {
var_dump($this->password . "------------" . Yii::$app->getSecurity()->validatePassword($this->password, $user->password) . "**********" . $user->password);
$this->addError($attribute, "Пароль или имя пользователя введены неверно");
}
}
}
Answer the question
In order to leave comments, you need to log in
var_dump($this->password . "------------" . Yii::$app->getSecurity()->validatePassword($this->password, $user->password) . "**********" . $user->password);
var_dump($this->password,Yii::$app->getSecurity()->validatePassword($this->password, $user->password), $user->password);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question