如果密码包含在要解析的字符串中,Password_verify() 给出 true

几天来我遇到了一个关于password_verify()的问题。在我的网址中输入密码失败之前我没有注意到这一点。


解释一下,我正在开发一个 Web 服务,为了进行身份验证,我需要在请求 URL 中使用密码和 ID。


这是我的代码


 if ($stmt->prepare("SELECT hashedPWD FROM `user` WHERE `id` = ?")){ // Trying to get the hashed pwd stored in DB

            $stmt->bind_param("i", $id);

            $stmt->execute();

            $stmt->bind_result($pwdHash); // $pwdHash contains the password hashed by password_hash() when the account was created

            $stmt->fetch();

            $stmt->close();

        }

$password = "test"; // The password in URL which is the good one

$isPwdGood = password_verify($password, $pwdHash);


var_dump($isPwdGood); // returns true, seems good right there


$password = "testtttttttttt"; // contains the real password with some others characters

  

$isPwdGood = password_verify($password, $pwdHash);


var_dump($isPwdGood); // returns also true

这里的问题是,当我想确认我的客户的身份时,我需要确保密码是他给我的密码,但是使用password_verify()我可以获得一个包含真实密码的错误密码,并且它会起作用。


狐的传说
浏览 70回答 1
1回答

慕哥6287543

我没有观看创建帐户的整个过程,应该这样做,因为我刚刚看到使用的函数是 crypt() 并且(我不知道为什么)它与以前的盐和哈希值配合得不好密码。我尝试切换到我向您展示的函数,即password_hash(),它效果更好!
打开App,查看更多内容
随时随地看视频慕课网APP