【发布时间】:2015-09-22 12:57:05
【问题描述】:
我正在使用Zend\Crypt\Password\Bcrypt 在数据库中存储加密的密码。不过现在仔细看了一下好像没看懂the verify method of this class:
/**
* Verify if a password is correct against a hash value
*
* @param string $password
* @param string $hash
* @throws Exception\RuntimeException when the hash is unable to be processed
* @return bool
*/
public function verify($password, $hash)
{
$result = crypt($password, $hash);
return Utils::compareStrings($hash, $result);
}
根据评论的功能“验证密码是否针对哈希值正确”
但是当我检查the php crypt function 时,它调用的第二个参数是一个可选的$salt,而不是一个$hash 要验证的字符串。
我的阅读方式:它首先使用传递的$hash 作为盐来加密我们要检查的$password,然后将它用作盐的相同$hash 与加密的$result 进行比较! ?
那么我在这里错过了什么? php-doc 不正确,或者我不明白发生了什么,或者我错过了文档中的某些内容。
【问题讨论】:
-
看到 Bcrypt 不应该通过比较 2 个字符串而是使用 password_verify() 来验证,这有点奇怪。我也想对此进行解释
-
@Crecket Zend\Crypt\Password\Bcrypt 是在将 password_* 函数添加到 PHP 核心之前创建的。
标签: php zend-framework2 bcrypt password-encryption