3 回答

TA貢獻(xiàn)1812條經(jīng)驗(yàn) 獲得超5個(gè)贊
// password encryption for security.
$salt = mcrypt_create_iv(22, MCRYPT_DEV_URANDOM);
$salt = base64_encode($salt);
$salt = str_replace('+', '.', $salt);
$hash = crypt($pass, '$2y$10$'.$salt.'$');
//echo ("".$hash."<br />\n");
$pass 是密碼輸入中的密碼
保存$hash到數(shù)據(jù)庫
使用從數(shù)據(jù)庫中獲得的密碼來驗(yàn)證密碼 $hash
if(password_verify($pass, $hash)) {
echo 'Password is valid!';
} else {
echo 'Invalid password.';
}
更新并嘗試該過程

TA貢獻(xiàn)1802條經(jīng)驗(yàn) 獲得超5個(gè)贊
//password encryption
$user_password = "1234";
$hash_pass = password_encryption($user_password, PASSWORD_BCRYPT, array('cost'=>10);
//"$user_password"-password obtained from the user input
//"$hash_pass" -encrypted password stored in a database
//verify the user password with that obtained from the database
if(password_verify($user_password, $hash_pass)){
echo "password is valid";
}else{
echo "password is not valid";
}
試試這個(gè)。
- 3 回答
- 0 關(guān)注
- 192 瀏覽
添加回答
舉報(bào)