donglin5770 2017-04-29 12:13
浏览 148
已采纳

PHP:password_verify总是返回false

somehow I'm struggling with something that I expected to be straightforward. I created the following code just for testing purposes and I expected it to give the answer "valid password" in case the provided $login_password is "123456". But I always get "Invalid password."

$login_password = $_POST['login_password'];
$login_password_hash = password_hash($login_password, PASSWORD_DEFAULT);

$target_password = '123456';
$target_password_hash = password_hash($target_password, PASSWORD_DEFAULT);

if ( password_verify($login_password_hash, $target_password_hash) ) {
    echo "Valid password.";
    } 
else {
    echo "Invalid password.";
    }

I even get "Invalid password." when changing the password_verify to compare the same variable with itself:

password_verify($login_password_hash, $login_password_hash)

A little help is highly appreciated :)

  • 写回答

2条回答 默认 最新

  • dongyuhui0418 2017-04-29 12:16
    关注

    You need to pass simple text password without hash as first param

    if ( password_verify($login_password , $target_password_hash) ) {
        echo "Valid password.";
        } 
    else {
        echo "Invalid password.";
        }
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 乌班图ip地址配置及远程SSH
  • ¥15 怎么让点阵屏显示静态爱心,用keiluVision5写出让点阵屏显示静态爱心的代码,越快越好
  • ¥15 PSPICE制作一个加法器
  • ¥15 javaweb项目无法正常跳转
  • ¥15 VMBox虚拟机无法访问
  • ¥15 skd显示找不到头文件
  • ¥15 机器视觉中图片中长度与真实长度的关系
  • ¥15 fastreport table 怎么只让每页的最下面和最顶部有横线
  • ¥15 java 的protected权限 ,问题在注释里
  • ¥15 这个是哪里有问题啊?