PHP说帐户密码错误

时间:2018-08-06 07:57:28

标签: php mysqli

当我输入错误的用户名时,它说“找不到用户”。正确,但是当我输入正确的用户名和密码时,它显示“密码错误”。

$sql = "SELECT Password FROM accounts WHERE Username = '".$username."' ";
$result = mysqli_query($conn, $sql);

if (mysqli_num_rows($result) > 0) {
    while ($row = mysqli_fetch_assoc($result)) {
        if (password_verify($password, $row['Password'])) {
            echo "Login successful.";
        } else {
            echo "Password incorrent.";
        }
    }
} else {
    echo "User not found.";
}

密码像这样被散列:

$hashed_password = password_hash($password, PASSWORD_DEFAULT);

0 个答案:

没有答案