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

      1. <small id='0juO1'></small><noframes id='0juO1'>

        未使用函数 password_verify 验证密码

        时间:2023-07-29

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

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

                  <tbody id='pUAZ9'></tbody>
                <tfoot id='pUAZ9'></tfoot>

                1. <legend id='pUAZ9'><style id='pUAZ9'><dir id='pUAZ9'><q id='pUAZ9'></q></dir></style></legend>
                  <i id='pUAZ9'><tr id='pUAZ9'><dt id='pUAZ9'><q id='pUAZ9'><span id='pUAZ9'><b id='pUAZ9'><form id='pUAZ9'><ins id='pUAZ9'></ins><ul id='pUAZ9'></ul><sub id='pUAZ9'></sub></form><legend id='pUAZ9'></legend><bdo id='pUAZ9'><pre id='pUAZ9'><center id='pUAZ9'></center></pre></bdo></b><th id='pUAZ9'></th></span></q></dt></tr></i><div id='pUAZ9'><tfoot id='pUAZ9'></tfoot><dl id='pUAZ9'><fieldset id='pUAZ9'></fieldset></dl></div>
                  本文介绍了未使用函数 password_verify 验证密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我想我已经使用函数 PASSWORD 直接从 mysql 数据库中散列密码(我在这里做错了吗?).我正在尝试使用此代码验证该密码:

                  I think i have hashed password using function PASSWORD directly from mysql database(am i doing wrong here?). And i am trying to verify that password with this code:

                      if($submit)
                      {
                          $first=$_POST['first'];
                          $password=$_POST['password'];
                          $hash="*85955899FF0A8CDC2CC36745267ABA38EAD1D28"; //this is the hashed password i got by using function PASSWORD in database
                          $password=password_verify($password,$hash);
                          $db = new mysqli("localhost", "root","","learndb");
                          $sql = "select * from admin where username = '" . $first . "' and password = '". $password . "'";
                          $result = $db->query($sql);
                          $result=mysqli_num_rows($result);
                  
                  
                          if($result>0)
                      {
                  
                          session_start();
                          $_SESSION['logged_in'] = true;
                          session_regenerate_id(true);
                          header("Location:loginhome.php");
                  
                      }
                  }
                  

                  但是密码不匹配.我在这里错过了什么?

                  But the password is not matching. What am i missing here?

                  更新:

                  在所有的建议之后,我使用了 php 代码中的 password_hash 来存储到数据库中.

                  After all the suggestions i have used password_hash from php code to store into database.

                  $db = new mysqli("localhost", "root","","learndb");
                  $password=password_hash('ChRisJoRdAn123',PASSWORD_DEFAULT);
                  $sql="INSERT INTO admin (username,password)values('ChrisJordan','$password')";
                  $db->query($sql);
                  

                  密码仍然不匹配.

                  推荐答案

                  无法在数据库中搜索加盐密码哈希.要计算散列,您需要使用 password_hash() 函数,因为您已经在插入语句中正确执行了.

                  One cannot search for a salted password hash in a database. To calculate the hash you need the password_hash() function as you already did correctly in your insert statement.

                  // Hash a new password for storing in the database.
                  // The function automatically generates a cryptographically safe salt.
                  $hashToStoreInDb = password_hash($password, PASSWORD_DEFAULT);
                  

                  要检查密码,您首先需要仅按用户名搜索(使用准备好的查询来避免 sql 注入):

                  To check a password, you first need to search by username only (used a prepared query to avoid sql injection):

                  $sql = 'select * from admin where username = ?';
                  $db->prepare($sql);
                  $db->bind_param('s', $first);
                  

                  当你最终从数据库中得到存储的哈希值时,可以这样检查:

                  When you finally got the stored hash from the database, it can be checked like this:

                  // Check if the hash of the entered login password, matches the stored hash.
                  // The salt and the cost factor will be extracted from $existingHashFromDb.
                  $isPasswordCorrect = password_verify($password, $existingHashFromDb);
                  

                  这篇关于未使用函数 password_verify 验证密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:mysqli查询只返回第一行 下一篇:mysqli_prepare() 期望参数 1 是 mysqli

                  相关文章

                  最新文章

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

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

                      <tfoot id='od44Z'></tfoot>