加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 站长学院 > MySql教程 > 正文

php – 为什么password_verify返回false?

发布时间:2020-12-11 23:53:33 所属栏目:MySql教程 来源:网络整理
导读:我正在使用password_verify来检查我的哈希密码.我有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

我正在使用password_verify来检查我的哈希密码.我有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上得到了错误.我已经检查了帖子值和mysql user_password_hash返回.

我不知道为什么它会返回假

有任何想法吗?

最佳答案 可能问题在于您的色谱柱长度,来自手册:
建议将结果存储在数据库列中,该列可以扩展到超过60个字符(255个字符将是一个不错的选择). link

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读