lithium\security\Password::check PHP Method

check() public static method

Compares a password and its hashed value using PHP's crypt(). Rather than a simple string comparison, this method uses a constant-time algorithm to defend against timing attacks.
See also: lithium\security\Password::hash()
See also: lithium\security\Password::salt()
public static check ( string $password, string $hash ) : boolean
$password string The user-supplied plaintext password to check.
$hash string The known hashed password to compare it to.
return boolean Returns a boolean indicating whether the password is correct.
    public static function check($password, $hash)
    {
        return String::compare($hash, crypt($password, $hash));
    }

Usage Example

Beispiel #1
0
 /**
  * testPassword method
  */
 public function testPassword()
 {
     $pass = '******';
     $bfSalt = "{^\\\$2a\\\$06\\\$[0-9A-Za-z./]{22}\$}";
     $bfHash = "{^\\\$2a\\\$06\\\$[0-9A-Za-z./]{53}\$}";
     $xdesSalt = "{^_zD..[0-9A-Za-z./]{4}\$}";
     $xdesHash = "{^_zD..[0-9A-Za-z./]{15}\$}";
     $md5Salt = "{^\\\$1\\\$[0-9A-Za-z./]{8}\$}";
     $md5Hash = "{^\\\$1\\\$[0-9A-Za-z./]{8}\\\$[0-9A-Za-z./]{22}\$}";
     // Make it faster than the default settings, else we'll be there tomorrow
     foreach (array('bf' => 6, 'xdes' => 10, 'md5' => null) as $method => $log2) {
         $salts = array();
         $hashes = array();
         $count = 20;
         $saltPattern = ${$method . 'Salt'};
         $hashPattern = ${$method . 'Hash'};
         for ($i = 0; $i < $count; $i++) {
             $salt = Password::salt($method, $log2);
             $this->assertPattern($saltPattern, $salt);
             $this->assertFalse(in_array($salt, $salts));
             $salts[] = $salt;
             $hash = Password::hash($pass, $salt);
             $this->assertPattern($hashPattern, $hash);
             $this->assertEqual(substr($hash, 0, strlen($salt)), $salt);
             $this->assertFalse(in_array($hash, $hashes));
             $hashes[] = $hash;
             $this->assertTrue(Password::check($pass, $hash));
         }
     }
 }
All Usage Examples Of lithium\security\Password::check