【发布时间】:2016-04-17 02:54:29
【问题描述】:
我正在为db 中的唯一用户编写登录代码。
但是password_verify 函数似乎不起作用。当我echohash 来自db 和password 写在表格中时,我看到了它们,所以查询或$_POST 没有问题。
这是我的代码: 登录:
$passwordFromForm = htmlspecialchars($_POST['password']);
$nmbr = 12; // it's the user's id.
$sql = "SELECT * FROM user WHERE iduser = $nmbr";
$res = mysqli_query($conn, $sql);
// $row = mysqli_fetch_assoc($res);
while($row = $res->fetch_assoc()) {
$hashFromDB = $row['hash'];
}
if(password_verify($passwordFromForm, $hashFromDB)) {
echo "success";
header("Location: ../admin.php");
}
else {
echo "The hash is:" . $hashFromDB . "and the pass is:" . $passwordFromForm;
//this echoes the correct hash and string
}
提前致谢。
【问题讨论】: