示例#1
0
 public function testPasswordHash()
 {
     $password = '******';
     $hash = Security::generatePasswordHash($password);
     $this->assertTrue(Security::validatePassword($password, $hash));
     $this->assertFalse(Security::validatePassword('test', $hash));
 }
 public function testRegister()
 {
     $this->specify('user should be registered', function () {
         $user = new User(['scenario' => 'register']);
         $user->username = '******';
         $user->email = '*****@*****.**';
         $user->password = '******';
         verify($user->register())->true();
         verify($user->username)->equals('tester');
         verify($user->email)->equals('*****@*****.**');
         verify(Security::validatePassword('tester', $user->password_hash))->true();
     });
     $this->specify('profile should be created after registration', function () {
         $user = new User(['scenario' => 'register']);
         $user->username = '******';
         $user->email = '*****@*****.**';
         $user->password = '******';
         verify($user->register())->true();
         verify($user->profile->gravatar_email)->equals('*****@*****.**');
     });
 }
示例#3
0
 /**
  * @param string $password password to validate
  * @return bool if password provided is valid for current user
  */
 public function validatePassword($password)
 {
     return Security::validatePassword($password, $this->password_hash);
 }
示例#4
0
 /**
  * Wrapper for yii security helper method.
  *
  * @param $password
  * @param $hash
  * @return bool
  */
 public static function validate($password, $hash)
 {
     return Security::validatePassword($password, $hash);
 }
示例#5
0
 /**
  * Validates the password.
  */
 public function validatePassword()
 {
     if ($this->user === null || !Security::validatePassword($this->password, $this->user->password_hash)) {
         $this->addError('password', \Yii::t('user', 'Invalid login or password'));
     }
 }