我正在尝试过渡到 Blowfish 以获取身份验证系统。请耐心等待,我不是密码学家,我对 Blowfish 的理解还不完全。
当前设置使用 sha1 和 salts。为每个用户生成盐并存储在数据库中。归结为:
$salt = $this->getSalt($username);
$hash = sha1($password . $salt);
if ($hash == $hashInDB)
{
// user is authenticated, set session id etc ...
}
该getSalt()
方法为指定用户获取存储在数据库中的盐。
现在,如果我正确理解了所有内容,那么使用 crypt 我应该这样做:
$salt = '$2a$07$' . $this->getSalt($username) . '$';
$hash = crypt($password, $salt);
if ($hash == crypt($password, $saltInDB))
{
// The user is authenticated, set session id etc..
}
澄清一下,对于第二个示例,$saltInDB
变量是一个类似于“$2a$07$arandomsaltcreatedatregistration$”的值。
- 我做对了吗?