1. <legend id='NykDC'><style id='NykDC'><dir id='NykDC'><q id='NykDC'></q></dir></style></legend>

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

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

        对现有密码使用 password_verify

        时间:2023-07-29

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

              1. <legend id='yw8xP'><style id='yw8xP'><dir id='yw8xP'><q id='yw8xP'></q></dir></style></legend>

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

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

                  问题描述

                  我正在尝试在某人登录我的网站之前检查其密码和用户名.密码都存储在 password_hash($password1, PASSWORD_BCRYPT); 我不确定我做错了什么.目前,无论我输入什么,它总是说不正确.

                  I'm trying to check the password and username of someone before they log in to my website. The passwords are all stored in password_hash($password1, PASSWORD_BCRYPT); I'm not sure as to what I'm doing wrong. At the moment, No matter what I type in, It always says Incorrect.

                  <?php
                  require 'privstuff/dbinfo.php';
                  
                  $username = $_POST["username"];
                  $password1 = $_POST["password1"];
                  
                  $mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
                  
                  if(mysqli_connect_errno()) {
                      echo "Connection Failed. Please send an email to owner@othertxt.com regarding this problem.";
                      exit();
                  }
                  
                  if ($stmt = $mysqli->prepare("SELECT `username`, `password` FROM `accounts` WHERE username = ? AND password = ?")) {
                  
                  
                      $result = mysqli_query($mysqli,"SELECT `password` FROM `accounts` WHERE username = $username");
                  
                      $stmt->bind_param("ss", $username, password_verify($password1, $result);
                      $stmt->execute();
                      $stmt->store_result();
                      if ($stmt->num_rows) {
                          echo("Success");
                      }
                      else {
                          echo("Incorrect");
                      }
                  
                  }
                  $mysqli->close(); 
                  
                  ?>
                  

                  这是 register.php

                  This is the register.php

                  <?php
                  require 'privstuff/dbinfo.php';
                  
                  $firstname = $_POST["firstname"];
                  $password1 = $_POST["password1"];
                  $email = $_POST["email"];
                  $ip = $_SERVER['REMOTE_ADDR'];
                  $username = $_POST["username"];
                  
                  $mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
                  
                  
                  if(mysqli_connect_errno()) {
                      echo "Connection Failed. Please send an email to owner@othertxt.com regarding this problem.";
                      exit();
                  }
                  
                          if ($stmt = $mysqli->prepare("INSERT INTO `accounts`(`firstname`, `username`, `password`, `email`, `ip`) VALUES (?,?,?,?,?)")) {
                  
                              $db_pw = password_hash($password1, PASSWORD_BCRYPT);
                  
                              $stmt->bind_param("sssss", $firstname, $username, $db_pw, $email, $ip);
                              $stmt->execute();
                              if ($stmt->affected_rows > 0) {
                  
                                  echo "Account successfuly created";
                              }
                              $stmt->close();
                      }
                      $stmt->close();
                  
                  $mysqli->close(); 
                  
                  ?>
                  

                  推荐答案

                  我解决了这个问题.. 我错误地使用了 password_verify.

                  I fixed the issue.. I was using password_verify incorrectly.

                  <?php
                  require 'privstuff/dbinfo.php';
                  
                  
                  $username = $_POST["username"];
                  $password1 = $_POST["password1"];
                  
                  $mysqli = new mysqli(DB_SERVER, DB_USER, DB_PASSWORD, DB_DATABASE);
                  
                  // Check connection
                  if(mysqli_connect_errno()) {
                      echo "Connection Failed: " . mysqli_connect_errno();
                      exit();
                  }
                  
                  /* create a prepared statement */
                  if ($stmt = $mysqli->prepare("SELECT `password` FROM `accounts` WHERE username = ?")) {
                  
                      /* Bind parameters: s - string, b - blob, i - int, etc */
                      $stmt -> bind_param("s", $username);
                  
                      /* Execute it */
                      $stmt -> execute();
                  
                      /* Bind results */
                      $stmt -> bind_result($result);
                  
                      /* Fetch the value */
                      $stmt -> fetch();
                  
                      /* Close statement */
                      $stmt -> close();
                  }
                  
                  
                  if(password_verify($password1, $result))
                  {
                      session_start();
                      $_SESSION['loggedin'] = true;
                      $_SESSION['username'] = $username;
                  
                     echo '<script type="text/javascript"> window.open("textbomber.php","_self");</script>';
                  }else{
                      echo '<script type="text/javascript"> alert("Incorrect Username/Password"); window.open("login.html","_self");</script>'; 
                  }
                  
                  $mysqli->close(); 
                  ?>
                  

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

                  上一篇:使用 MySQLi 准备语句时无法获取行数和获取 下一篇:php print_r 中显示的二进制文件内容但未保存在

                  相关文章

                  最新文章

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

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

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