使用PHP 5.5的password_hash和password_verify函數假設我想為用戶存儲密碼,這是使用PHP 5.5的password_hash()功能(或者這個版本的PHP 5.3.7+:https://github.com/ircmaxell/password_compat)的正確方法嗎?$options = array("cost" => 10, "salt" => uniqid());$hash = password_hash($password, PASSWORD_BCRYPT, $options);然后我會這樣做:mysql_query("INSERT INTO users(username,password, salt) VALUES($username, $hash, " . $options['salt']);要插入數據庫。然后驗證:$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}
添加回答
舉報
0/150
提交
取消