Password_verify()返回False和正确的密码

时间:2019-04-15 13:08:10

标签: php database mongodb

我正在尝试使用PHP和MongoDB创建一个登录页面。登录时,我输入的密码为<input type="text" name="password" placeholder="Password">,在PHP代码中,我使用password_verify进行验证。即使输入了正确的密码,我也得到了错误的密码作为输出。

if(isset($_POST['login'])){
        print_r($_POST);


        $email = $_POST['email'];
        $upass = $_POST['password'];
        $criteria = array("email"=> $email);
        $query = $usercollection->findOne($criteria);
        var_dump($query);
        if(empty($query)){
            echo "Email ID is not registered.";
            echo "Either <a href='register.html'>Register</a> with the new Email ID or <a href='loginuser.html'>Login</a> with an already registered ID";
        }
        else{

            $pass = $query["password"];
                if(password_verify($upass,$pass)){
                $var = setsession($email);
                print_r($_SESSION);
                echo "Password match";

                if($var){

                    /*header("Location: home.php");*/ echo "Login success";
                }
                else{
                    echo "Some error";
                }
            }
            else{
                echo "Password not match";
                echo "You have entered a wrong password";
                echo "<br>";
                echo "Either <a href='register.html'>Register</a> with the new Email ID or <a href='loginuser.html'>Login</a> with an already registered ID";
            }
        }
    }

1 个答案:

答案 0 :(得分:-2)

password_verify()将您的输入密码与数据库中存储的哈希进行匹配。 确保使用password_hash()函数将密码另存为哈希值在数据库中