php - password_verify 始终返回 true
问题描述
我正在登录页面上工作,偶然发现了这个问题,无论我写什么密码,我都可以登录。
我检查了 $password、$row['password']、$pwdCheck 的值,它们都具有它们需要的值。
散列密码保存在 varchar(255) 中。我仔细检查了名字和我想到的一切,但如果你想到了什么,请告诉我。据我所知,问题在于密码验证。
我知道这不是制作登录页面的最佳做法,但现在它可以工作。
谢谢
<?php
if ( isset($_POST['login-submit']) ) {
require '../../files/includes/functions.php';
$mysqli = get_db();
$email = $_POST['email'];
$password = $_POST['password'];
// check if the email is in the database
$sql ='SELECT * FROM taxisvl_diritems WHERE email =?';
$stmt = mysqli_stmt_init($mysqli);
if ( empty($email) || empty($password) ) {
header("Location: /inloggen?error=emptyfields");
exit();
}
else {
// check to see if we can run the query
if ( !mysqli_stmt_prepare($stmt,$sql) ) {
header("Location: /inloggen?error=sqlerror");
exit();
}
else {
// bind the value to the parameter in the query statement
mysqli_stmt_bind_param($stmt, 's', $email);
// run the query
mysqli_stmt_execute($stmt);
$result = mysqli_stmt_get_result($stmt);
// check if we have a result for the given email
if ( $row = mysqli_fetch_assoc($result) ) {
// check the password
$pwdCheck = password_verify($password, $row['password']);
if ( $pwdCheck = true) {
// user is logged in
// create sessions to retreive users info
$_SESSION['id'] = $row['id'];
$_SESSION['email'] = $row['email'];
$_SESSION['name'] = $row['name'];
header("Location: /dashboard");
exit();
}
else {
header("Location: /inloggen?error=wrngpassword");
exit();
}
}
else {
header("Location: /inloggen?error=wrngemail");
exit();
}
}
}
} else {
echo 'Login not set';
}
?>```
解决方案
推荐阅读
- mysql - 从 SQL 中的同一行返回最小值的列名
- c++ - 如何修复 libCGAL-vc140-mt-4.14-l-900.lib 链接错误(VCPKG CGAL 更新 4.14)
- cloudflare - Cloudflare UI 快把我逼疯了,这个按钮是打开还是关闭?
- java - 容器 Bean 透明地代理 get/set 到容器
- c++ - 我有 12 个 CPU,1 个插槽,每个插槽 6 个内核,每个内核 2 个线程 - 这些信息如何对应于 MPI 和 OpenMP 的并行化?
- matlab - 替换字符串中的坏字符 Matlab
- makefile - 为 Sparc 交叉编译编译 OpenBIOS
- php - 如何检查通过的时间戳是否在php中是微的
- wordpress - 如何将自定义媒体元素添加到 wordpress 页面
- ios - 上传到 Appstore 的问题:不包括符号/配置文件 (LINEA PRO)