0
我猜標題很自我解釋。我在我的login.php中使用了password_hash函數。當我查看數據庫時,我看到密碼未被散列。這是正確的還是我做錯了什麼?這裏是我的一段代碼(safe_post_value是我自己的函數來逃避字符串):使用password_hash和password_verify,爲什麼數據庫中的密碼沒有被散列?
<?php
session_start();
if (isset($_POST['submit'])) {
$username = $_POST['username'];
$password = $_POST['password'];
$safe_username = safe_post_value($username);
$safe_password = safe_post_value($password);
$hashed_password = password_hash($safe_password, PASSWORD_DEFAULT);
$verified_password = password_verify($password, $hashed_password);
$query = "SELECT * FROM `members` WHERE '$safe_username' = `username`";
$result = mysqli_query($connection, $query);
if ($result = mysqli_query($connection, $query)) {
if ($verified_password){
while ($row = mysqli_fetch_assoc($result)) {
printf("%s, %s\n", $row['username'], $row['password']);
}
}
} else {
$message = "error";
echo $message;
}
mysqli_free_result($result);
}
?>
<form action="login.php" method="POST">
<input type="text" name="username" placeholder="gebruikersnaam">
<input type="password" name="password" placeholder="wachtwoord">
<input type="submit" name="submit" value="verstuur">
</form>
因此,要明確一點:這個代碼工作,但我只是想知道,這是正常的,密碼是不是哈希在數據庫中。
密碼應在數據庫中進行散列,但是你在這裏所做的是打與用戶輸入的密碼,並檢查它作爲一個純文本值....你的代碼是在哪裏設置用戶的密碼,然後將其存儲在數據庫中? –
您沒有向我們展示將其放入數據庫中的代碼。 – SLaks
你可以顯示插入密碼的代碼嗎? – Jim