Ejemplo n.º 1
0
 /**
  * @param string $attribute
  * @param array $params
  */
 public function validatePassword($attribute, $params)
 {
     if (!$this->hasErrors()) {
         if (!$this->_user->validatePassword($this->{$attribute})) {
             $this->addError($attribute, Yii::t('app', 'ERROR_WRONG_CURRENT_PASSWORD'));
         }
     }
 }
Ejemplo n.º 2
0
 /**
  * @param string $attribute
  * @param array $params
  */
 public function validatePassword($attribute, $params)
 {
     if (!$this->hasErrors()) {
         if (!$this->_user->validatePassword($this->{$attribute})) {
             $this->addError($attribute, 'Неверный адрес или пароль');
         }
     }
 }
Ejemplo n.º 3
0
 public function testUserPasswordValidation()
 {
     $user = new User(['username' => 'test', 'email' => '*****@*****.**', 'password' => 'secretpassword']);
     $this->assertTrue($user->save());
     $this->assertNotNull($user->auth_key);
     $this->specify('i can validate passwords', function () use($user) {
         expect('invalid password is not verified', $user->validatePassword('wrongpw'))->false();
         expect('valid password is verified', $user->validatePassword('secretpassword'))->true();
     });
 }
Ejemplo n.º 4
0
 /**
  * Signs user up
  *
  * @param User $user
  * @return User|null the saved model or null if saving fails
  */
 public function changePassword($user)
 {
     if ($this->validate()) {
         if ($user->validatePassword($this->currentPassword)) {
             $user->setPassword($this->password);
             $user->generateAuthKey();
             if ($user->save()) {
                 return $user;
             }
         } else {
             $this->addError('currentPassword', 'Current password is incorrect');
         }
     }
     return null;
 }
Ejemplo n.º 5
0
 /**
  * Finds user by username and password
  *
  * @param string $username
  * @param string $password
  * @return static|null
  */
 public function Auth($username, $password)
 {
     // username, password are mandatory fields
     if (empty($username) || empty($password)) {
         return null;
     }
     // Yii::$app->getSecurity()->generatePasswordHash($this->password);
     // get user using requested username
     $user = User::findOne(['username' => $username]);
     if (empty($user)) {
         return null;
     }
     // validate password
     $this->password = $user->password;
     $isPass = User::validatePassword($password);
     // if password validation fails
     if (!$isPass) {
         return null;
     }
     // if user validates (both user_email, user_password are valid)
     return $user;
 }
Ejemplo n.º 6
0
 public function testValidatePassword()
 {
     $user = new User();
     $user->load($this->user['user1'], false);
     $this->assertTrue($user->validatePassword("yiibook"));
 }
Ejemplo n.º 7
0
 public function userPasswordValidator($attribute, $params)
 {
     if (!$this->_user->validatePassword($this->{$attribute})) {
         $this->addError($attribute, 'Please enter correct old password.');
     }
 }
Ejemplo n.º 8
0
 public function testUserValidatePassword()
 {
     $user = new User();
     expect_not($user->validatePassword(''));
     $user = User::findByEmail('*****@*****.**');
     expect_that($user->validatePassword('123123'));
     expect_not($user->validatePassword('test_password'));
 }