common\models\User::setPassword PHP Method

setPassword() public method

Generates password hash from password and sets it to the model
public setPassword ( string $password )
$password string
    public function setPassword($password)
    {
        $this->password_hash = Yii::$app->security->generatePasswordHash($password);
    }

Usage Example

 public function resetPassword()
 {
     $this->_user = User::findIdentity(Yii::$app->user->id);
     if (!Yii::$app->getSecurity()->validatePassword($this->password, $this->_user->password_hash)) {
         throw new InvalidParamException(Yii::t('User', 'source_password_error'));
     }
     $this->_user->setPassword($this->new_password);
     return $this->_user->save(false);
 }
All Usage Examples Of common\models\User::setPassword