我已經使用this和this的密碼哈希腳本,我得到它的除了一些時間地穴功能給哈希爲「* 0」正常工作,並那麼它就會失敗。crypt()函數沒有給予適當的哈希
PHP代碼
$password='password';
$salt = '$2y$07$';
$salt .= base64_encode(mcrypt_create_iv(16, MCRYPT_DEV_RANDOM));
$salt .='$$';
$password_hash = crypt($password, $salt)';
echo $password_hash.'<br />';
使用上面我得到的值作爲
$salt = '$2y$07$8K3i8rJ7n7bsJA36CfbabQ==$$';
$crypt_password = $password_hash;
$crypt_password = '$2y$07$8K3i8rJ7n7bsJA36CfbabO9ojj2hl61azl8CubJQhRTgla4ICiCVC';
if (crypt($password,$crypt_password)===$crypt_password)
{
echo 'password verified';
}
else{
echo 'password NOT verified';
}
請參閱並提出任何可能的方式,使其正常工作。
謝謝。
'$ crypt_password = $ password_hash'對不起,我沒有提到上述 –
肯定的,因爲鹽必須是隨機的。 –
驗證步驟是正確的('crypt'從'crypt'返回的「散列」中提取鹽)。問題是,'base64_encode'會發出無效字符,例如'+'(接受字符''crypt':'「./0-9A-Za-z」')。如果'base64_encode'返回一個無效字符'「* 0」'返回。 – vstm