使用PHP 5.5的password_hash和password_verify函數(shù)假設(shè)我想為用戶(hù)存儲(chǔ)密碼,這是使用PHP 5.5的password_hash()功能(或者這個(gè)版本的PHP 5.3.7+:https://github.com/ircmaxell/password_compat)的正確方法嗎?$options = array("cost" => 10, "salt" => uniqid());$hash = password_hash($password, PASSWORD_BCRYPT, $options);然后我會(huì)這樣做:mysql_query("INSERT INTO users(username,password, salt) VALUES($username, $hash, " . $options['salt']);要插入數(shù)據(jù)庫(kù)。然后驗(yàn)證:$row = mysql_fetch_assoc(mysql_query("SELECT salt FROM users WHERE id=$userid"));$salt = $row["salt"];$hash = password_hash($password, PASSWORD_BCRYPT, array("cost" => 10, "salt" => $salt));if (password_verify($password, $hash) {
// Verified}
使用PHP 5.5的password_hash和password_verify函數(shù)
當(dāng)年話(huà)下
2019-07-27 10:28:04