【问题标题】:Password_verify bcrypt not workingPassword_verify bcrypt 不起作用
【发布时间】:2015-06-02 14:16:22
【问题描述】:

感谢您在这个问题上帮助我。我正在尝试将密码与 php password_verify 进行比较,但它不起作用。我的代码有问题吗? (我收到第二条消息“无效用户或密码”)干杯!

function login_aut($uname, $pass){

     include('_con.php');
     include('password.php');

    $stmt = $conex->prepare("SELECT id, pass FROM tb_users WHERE uname =?");

    /* bind parameters for markers */
    $stmt->bind_param("s", $uname);

    /* execute query */
    $stmt->execute();

    /* get num of rows */
    $stmt->store_result();
    $numrows = $stmt->num_rows;

    if(($numrows) == ""){echo 'INVALID USER ';die();}

    $stmt->bind_result($u_id,$upass);

    $stmt->fetch();
    /* close statement */
    $stmt->close();



if (!password_verify($pass,$upass)) { echo 'INVALID USER OR PASSWORD'; die(); }

【问题讨论】:

  • 做过调试,比如var_dump($pass, $upass)? $numrows == "" 无效。 num_rows 返回一个整数,您不应该与字符串进行比较,即使 0 == ""true
  • 也闻起来像变量作用域
  • 谢谢@MarcB var_dump 没问题。 =/
  • $upass 一个哈希,还是一​​个明文密码或者什么?
  • 并将 $stmt->execute(); 更改为 if(!$stmt->execute()){trigger_error("there was an error....".$conex->error, E_USER_WARNING);} 以了解潜在的数据库错误。还要确保您的列长度足够长以容纳散列。看到这种情况经常发生。加上不带login_aut() 功能的尝试。也可能是范围问题。

标签: php passwords prepared-statement


【解决方案1】:

感谢大家的帮助!问题在于 DB 列的长度,它对于哈希来说不够长。谢谢!

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2015-11-16
    • 1970-01-01
    • 2018-02-27
    • 2017-06-18
    • 2022-07-02
    • 1970-01-01
    • 2014-09-29
    • 1970-01-01
    相关资源
    最近更新 更多