【发布时间】: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