为什么 password_verify 返回 false? [英] Why is password_verify returning false?
本文介绍了为什么 password_verify 返回 false?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用 password_verify
来检查我的散列密码.我有 PHP 5.5:
I'm using a password_verify
to check my hashed password. I have PHP 5.5:
$this->db_connection = new mysqli(DB_HOST, DB_USER, DB_PASS, DB_NAME);
// if no connection errors (= working database connection)
if (!$this->db_connection->connect_errno) {
// escape the POST stuff
$user_name = $this->db_connection->real_escape_string($_POST['user_name']);
// database query, getting all the info of the selected user (allows login via email address in the
// username field)
$sql = "SELECT user_name, user_email, user_password_hash
FROM users
WHERE user_name = '" . $user_name . "' OR user_email = '" . $user_name . "';";
$result_of_login_check = $this->db_connection->query($sql);
// if this user exists
if ($result_of_login_check->num_rows == 1) {
// get result row (as an object)
$result_row = $result_of_login_check->fetch_object();
// using PHP 5.5's password_verify() function to check if the provided password fits
// the hash of that user's password
if (password_verify($_POST['user_password'], $result_row->user_password_hash)) {
// write user data into PHP SESSION (a file on your server)
$_SESSION['user_name'] = $result_row->user_name;
$_SESSION['user_email'] = $result_row->user_email;
$_SESSION['user_login_status'] = 1;
我在 password_verify
上得到 false
.我已经检查了帖子值和 mysql user_password_hash 返回.
I'm getting false
on password_verify
. I've already checked the posts value and mysql user_password_hash return.
我不知道为什么它返回 false
I don't know why it's returning false
有什么想法吗?
推荐答案
可能是你的列长度有问题,来自手册:建议将结果存储在可以扩展到 60 个字符以上的数据库列中(255 个字符是一个不错的选择). link
Probably the problem is with your column length, from the manual: it is recommended to store the result in a database column that can expand beyond 60 characters (255 characters would be a good choice). link
这篇关于为什么 password_verify 返回 false?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文