Answer the question
In order to leave comments, you need to log in
CPasswordHelper::verifyPassword() how does it work?
It's not clear how it works, maybe I'm doing something wrong
UserIdentity.php
private $_id;
public function authenticate(){
$record = Users::model()->findByAttributes(array('login' => $this->username));
if($record === null){
$this->errorCode = self::ERROR_USERNAME_INVALID;
}else if(CPasswordHelper::verifyPassword($this->password, $record->password)){
$this->_id = $record->id;
$this->errorCode = self::ERROR_NONE;
}else{
$this->errorCode = self::ERROR_PASSWORD_INVALID;
}
return !$this->errorCode;
}
public function authenticate(){
$identity = new UserIdentity($this->login, $this->password);
if($identity->authenticate()){
Yii::app()->user->login($identity,3600*24*30);
return true;
}else{
$this->addError('password',"Неправильный логин или пароль.");
return false;
}
}
Answer the question
In order to leave comments, you need to log in
Users.php
public function hashPassword($password){
return CPasswordHelper::hashPassword($password);
}
public function validatePassword($password){
return CPasswordHelper::verifyPassword($password,$this->password);
}
public function authenticate(){
$user = Users::model()->findByAttributes(array('login' => $this->username));
if($user === null){
$this->errorCode = self::ERROR_USERNAME_INVALID;
}else if(!$user->validatePassword($this->password)){
$this->errorCode = self::ERROR_PASSWORD_INVALID;
}else{
$this->_id = $user->id;
$this->setState('login', $user->login);
$this->errorCode = self::ERROR_NONE;
}
return $this->errorCode == self::ERROR_NONE;
}
www.yiiframework.com/doc/api/1.1/CPasswordHelper#v...
that's how shitty it works. It simply generates a hash of the password and compares it. Not the most secure way.
The reasons for which authorization may not pass are - $this->password contains something incorrect, or you are passing an already hashed password, or an unhashed password in the user model, etc.
Good afternoon.
Have you resolved this issue? Faced this problem. I'm also sitting for the 2nd day)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question