<bdo id='R98ST'></bdo><ul id='R98ST'></ul>

  • <tfoot id='R98ST'></tfoot>

      <small id='R98ST'></small><noframes id='R98ST'>

    1. <legend id='R98ST'><style id='R98ST'><dir id='R98ST'><q id='R98ST'></q></dir></style></legend>
        <i id='R98ST'><tr id='R98ST'><dt id='R98ST'><q id='R98ST'><span id='R98ST'><b id='R98ST'><form id='R98ST'><ins id='R98ST'></ins><ul id='R98ST'></ul><sub id='R98ST'></sub></form><legend id='R98ST'></legend><bdo id='R98ST'><pre id='R98ST'><center id='R98ST'></center></pre></bdo></b><th id='R98ST'></th></span></q></dt></tr></i><div id='R98ST'><tfoot id='R98ST'></tfoot><dl id='R98ST'><fieldset id='R98ST'></fieldset></dl></div>

        PHP &amp;MYSQL:使用 bcrypt 哈希并使用数据库验证

        时间:2023-10-03

      1. <i id='fxxUs'><tr id='fxxUs'><dt id='fxxUs'><q id='fxxUs'><span id='fxxUs'><b id='fxxUs'><form id='fxxUs'><ins id='fxxUs'></ins><ul id='fxxUs'></ul><sub id='fxxUs'></sub></form><legend id='fxxUs'></legend><bdo id='fxxUs'><pre id='fxxUs'><center id='fxxUs'></center></pre></bdo></b><th id='fxxUs'></th></span></q></dt></tr></i><div id='fxxUs'><tfoot id='fxxUs'></tfoot><dl id='fxxUs'><fieldset id='fxxUs'></fieldset></dl></div>

          <bdo id='fxxUs'></bdo><ul id='fxxUs'></ul>

                1. <small id='fxxUs'></small><noframes id='fxxUs'>

                  <legend id='fxxUs'><style id='fxxUs'><dir id='fxxUs'><q id='fxxUs'></q></dir></style></legend>
                    <tbody id='fxxUs'></tbody>
                  <tfoot id='fxxUs'></tfoot>
                  本文介绍了PHP &amp;MYSQL:使用 bcrypt 哈希并使用数据库验证密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我正在使用 Andrew Moore 先生的方法 (您如何在 PHP 中使用 bcrypt 对密码进行散列处理?) 的散列用户密码.我所做的是我有一个注册页面,它使用

                  I'm using Mr. Andrew Moore's method (How do you use bcrypt for hashing passwords in PHP?) of hashing user's password. What I did is I have a registration page and it uses

                  $bcrypt = new Bcrypt(12);
                  $pass = $_POST['password']; //register password field
                  $hash= $bcrypt->hash($pass);
                  
                  // then inserts $hash into database with users registered email (I've checked my mysql database and it indeed has an hashed item
                  

                  然后我有一个登录页面,由电子邮件和密码字段组成.我的想法是电子邮件地址在我的数据库中是唯一的.因此,考虑到这一点,我制作了一个脚本,它首先检查用户的电子邮件地址,然后如果存在现有的电子邮件地址,请使用此验证哈希密码

                  Then I have a login page, consisting of email and password fields. My thought is that email addresses are unique in my database. So with that in mind, I made a script where it check's users email address first, then if there is an existing one, verify the hash password with this

                  $bcrypt = new Bcrypt(12);
                  
                  $email = $_POST['email']; //from login email field
                  $pass_l = $_POST['password']; // from login password field
                  $hash_1= $bcrypt->hash($pass_1);
                  
                  $chk_email= $dbh->prepare("SELECT password FROM table WHERE email = ?");
                  $chk_email -> execute(array($email));
                  
                  while($row = $chk_email->fetch(PDO::FETCH_ASSOC)){
                      $chk_pass = $row['password']; //inside a while loop to get the password
                      $pass_isGood = $bcrypt->verify($hash_1, $chk_pass);
                      var_dump($pass_isGood); // I'm getting false
                  
                  }
                  

                  我不确定我做错了什么,我应该说实话.我已经将我的 tablefield 设置为 text 甚至 varchar(256)

                  I'm not sure what I'm doing wrong, I'm supposed to get true. And I have set my tablefield to text or even varchar(256)

                  推荐答案

                  使用Andrew Moore的课,需要调用类 verify() 方法来验证用户的密码是否与哈希匹配.您传递给它的两个参数是用户输入的明文密码和您存储在数据库中的哈希值.

                  Using Andrew Moore's class, you need to call the class verify() method to verify that the user's password matches the hash. The two parameters you pass to it are the plaintext password the user entered and the hash that you stored in the database.

                  您似乎向 verify() 传递了第二个散列密码,这就是它不起作用的原因.将明文密码作为第一个参数传入.

                  It seems you passed a second hashed password to verify() instead, which is why it's not working. Pass in the plaintext password as the first argument.

                  这篇关于PHP &amp;MYSQL:使用 bcrypt 哈希并使用数据库验证密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:使用文件的一部分生成 JavaScript 文件哈希值 下一篇:JavaScript 中的 PHP 函数 crypt()

                  相关文章

                  最新文章

                    <bdo id='8i6uq'></bdo><ul id='8i6uq'></ul>

                  <small id='8i6uq'></small><noframes id='8i6uq'>

                  <i id='8i6uq'><tr id='8i6uq'><dt id='8i6uq'><q id='8i6uq'><span id='8i6uq'><b id='8i6uq'><form id='8i6uq'><ins id='8i6uq'></ins><ul id='8i6uq'></ul><sub id='8i6uq'></sub></form><legend id='8i6uq'></legend><bdo id='8i6uq'><pre id='8i6uq'><center id='8i6uq'></center></pre></bdo></b><th id='8i6uq'></th></span></q></dt></tr></i><div id='8i6uq'><tfoot id='8i6uq'></tfoot><dl id='8i6uq'><fieldset id='8i6uq'></fieldset></dl></div>
                      <tfoot id='8i6uq'></tfoot>
                      <legend id='8i6uq'><style id='8i6uq'><dir id='8i6uq'><q id='8i6uq'></q></dir></style></legend>