password_verify()函数返回一个空的var

时间:2019-01-22 06:11:24

标签: php password-encryption password-hash

我的password_verify函数没有返回任何内容,但是我认为我的代码还可以,我试图删除字符转义符,但结果仍然相同,请帮助 这是我的代码

<?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();
 }

1 个答案:

答案 0 :(得分:1)

password_verify()返回布尔值,如果$ pw为false,则echo $pw将不输出任何内容。

尝试使用正确和错误的密码测试2种情况。