我正在使用 password_compat.php 来使用 password_hash 和 password_verify 函数。我正在使用河豚算法。password_verify 似乎不起作用,它与数据库中存储的哈希不匹配。我是否必须使用 password_verify 指定算法或盐?
雷格斯特脚本:
$hash = password_hash($pass, PASSWORD_BCRYPT);
$qry = "INSERT INTO users (email, fname, lname, gender, p4s5) VALUES ('$email', '$fname', '$lname', '$gender', '$hash')";
$result = mysqli_query($dblink, $qry) or die(mysqli_error($dblink));
登录脚本:
$qry = "SELECT * FROM users WHERE email='$email' LIMIT 1";
$result = mysqli_query($dblink, $qry);
if (!mysqli_num_rows($result) > 0) {
// email not in database, error
$loginErrors .= "<li>Username or password wrong</li>";
} else {
$row = mysqli_fetch_assoc($result);
// verify password;
$hash = $row["p4s5"];
if (password_verify($pass, $hash)) {
// not same, error
$loginErrors .= "<li>Username or password wrong</li>";
} else {
// login user
$id = $row["id"];
$fname = $row["fname"];
$lname = $row["lname"];
login($id, $email, $fname, $lname);
header("Location: ".$_SESSION["last-page"]);
}
}
表结构:
创建表users
(
id
int(11) NOT NULL AUT...