Dcrypt\Hash::verify PHP Method

verify() public static method

Check the validity of a hash.
public static verify ( string $input, string $hash, string $password ) : boolean
$input string Input to test.
$hash string Known hash to validate against.
$password string HMAC password to use during iterative hash.
return boolean
    public static function verify($input, $hash, $password)
    {
        // Get the salt value from the decrypted prefix
        $salt = Str::substr($hash, 0, 16);
        // Get the encrypted cost bytes
        $cost = self::bin2dec(Otp::crypt(Str::substr($hash, 28, 4), $password));
        // Get the entire cost+hash blob for comparison
        $blob = Str::substr($hash, 16, 16);
        if (!Str::equal(self::costHash($cost, $salt, $password), $blob)) {
            return false;
        }
        // Return the boolean equivalence
        return Str::equal($hash, self::build($input, $password, $cost, $salt));
    }

Usage Example

Beispiel #1
0
 public function testVector()
 {
     $input = 'hello world';
     $key = 'password';
     $vector = base64_decode('TzYfV/BWvqbGDNaX8fK81PcNol+zgs7KMxelj9aOGmmMa9cRKZGXwVOlLBn4Z0qdnDDCpSg9AUqXHZyzVqzztA==');
     $this->assertTrue(Hash::verify($input, $vector, $key));
 }