为了账号安全,请及时绑定邮箱和手机立即绑定

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

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

PHP
狐的传说 2023-08-19 16:45:46
几天来我遇到了一个关于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()我可以获得一个包含真实密码的错误密码,并且它会起作用。
查看完整描述

1 回答

?
慕哥6287543

TA贡献1831条经验 获得超10个赞

我没有观看创建帐户的整个过程,应该这样做,因为我刚刚看到使用的函数是 crypt() 并且(我不知道为什么)它与以前的盐和哈希值配合得不好密码。

我尝试切换到我向您展示的函数,即password_hash(),它效果更好!

查看完整回答
反对 回复 2023-08-19
  • 1 回答
  • 0 关注
  • 65 浏览

添加回答

举报

0/150
提交
取消
意见反馈 帮助中心 APP下载
官方微信