對於存儲密碼進入數據庫
<?php
/**
* Note that the salt here is randomly generated.
* Never use a static salt or one that is not randomly generated.
*
* For the VAST majority of use-cases, let password_hash generate the salt randomly for you
*/
$options = [
'cost' => 11,
'salt' => mcrypt_create_iv(22, MCRYPT_DEV_URANDOM),
];
echo password_hash("rasmuslerdorf", PASSWORD_BCRYPT, $options)."\n";
?>
,如果你想使用password_verify()函數驗證密碼。
首先提取數據庫存儲的密碼,並使用password_verify()函數
<?php
// See the password_hash() example to see where this came from.
$hash = '$2y$11$lBi3B5rakkB6CBJRLn2e6O1RppUr2y5r0W/4Z0jJBGqE9cdYK.1sa';
if (password_verify('rasmuslerdorf', $hash)) {
echo 'Password is valid!';
} else {
echo 'Invalid password.';
}
?>
Click HERE TO CHECK
出了什麼問題,我的問題? – schenker
可能重複[在哪裏把密碼\ _verify登錄腳本?](http://stackoverflow.com/questions/32554085/where-to-put-password-verify-in-login-script) –