password_verify( ) 函数 returns 一个空变量
password_verify( ) function returns an empty var
我的 password_verify 函数没有 return 任何东西,但我认为我的代码没问题,我尝试删除字符转义但结果仍然相同,请帮忙
这是我的代码
<?php
if (isset($_POST['submit'])) {
include_once 'db.php';
$uname = stripcslashes($_POST['username']);
$pass = stripcslashes($_POST['userpassword']);
$uname = mysqli_real_escape_string($conn, $_POST['username']);
$pass = mysqli_real_escape_string($conn, $_POST['userpassword']);
//check if input characters are valid
if (!preg_match("/^[a-zA-Z0-9]*$/",$uname) || !preg_match("/^[a-zA- Z0-9]*$/",$pass)) {
header("Location: ../index.php?signin=invalidwords");
exit();
}else {
//validate username n pwd
$sql = "SELECT * FROM loginAcc WHERE position='$uname'";
$result = mysqli_query($conn,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$count = mysqli_num_rows($result);
$hashedpwd = $row['userpassword'];
$pw = password_verify($pass,$hashedpwd);
echo $pass."<br />";
echo $hashedpwd."<br />";
echo $pw;
}
}else{
header("Location: ../login.php");
exit();
}
password_verify()
return bool 值,如果你的 $pw 为假,那么 echo $pw
将不打印任何内容。
尝试用正确和错误的密码测试2个案例。
我的 password_verify 函数没有 return 任何东西,但我认为我的代码没问题,我尝试删除字符转义但结果仍然相同,请帮忙 这是我的代码
<?php
if (isset($_POST['submit'])) {
include_once 'db.php';
$uname = stripcslashes($_POST['username']);
$pass = stripcslashes($_POST['userpassword']);
$uname = mysqli_real_escape_string($conn, $_POST['username']);
$pass = mysqli_real_escape_string($conn, $_POST['userpassword']);
//check if input characters are valid
if (!preg_match("/^[a-zA-Z0-9]*$/",$uname) || !preg_match("/^[a-zA- Z0-9]*$/",$pass)) {
header("Location: ../index.php?signin=invalidwords");
exit();
}else {
//validate username n pwd
$sql = "SELECT * FROM loginAcc WHERE position='$uname'";
$result = mysqli_query($conn,$sql);
$row = mysqli_fetch_array($result,MYSQLI_ASSOC);
$count = mysqli_num_rows($result);
$hashedpwd = $row['userpassword'];
$pw = password_verify($pass,$hashedpwd);
echo $pass."<br />";
echo $hashedpwd."<br />";
echo $pw;
}
}else{
header("Location: ../login.php");
exit();
}
password_verify()
return bool 值,如果你的 $pw 为假,那么 echo $pw
将不打印任何内容。
尝试用正确和错误的密码测试2个案例。