title: Unable to extract password hash from database with prepared statements
body: <p><strong>EDIT:</strong> To clarify, I am unable to extract the hashed password from my database using prepared statements.</p>
  
  <p>I'm trying to create a login system that uses prepared statements, password_hash and password_verify.</p>
  
  <p>I have created the registering form that creates the user, with the hashed password using <code>password_hash($_POST['password'], PASSWORD_DEFAULT);</code></p>
  
  <p>This works properly.</p>
  
  <p>However, I am now stuck on creating the login form.</p>
  
  <p>I am trying to get the password hash that gets stored when a user registers but I cannot get it to work with prepared statements.</p>
  
  <p>This is what I currently have.</p>
  
  <pre><code>&lt;?php
  require('db.php');
  
  if(isset($_POST['submit'])) {
    $stmt = $connect-&gt;prepare('SELECT user_name, user_password FROM `users` WHERE user_name = ?');
  
    if($stmt) {
      $username = $_POST['username'];
      $password = $_POST['password'];
  
      $stmt-&gt;bind_param('s', $username);
  
      $stmt-&gt;execute();
  
    }
  }
  
  ?&gt;
  </code></pre>
  
  <p>How do I use the data that I got from the select query? And how do I use it to verify the password?</p>
  
  <p>I tried:</p>
  
  <pre><code>$stmt-&gt;store_result();
  $stmt-&gt;bind_result($loginUsername, $hash);
  </code></pre>
  
  <p>That only stored the username, but not the password hash and I have no clue why.</p>
  
  <p>Verifying the password would use this?
  <code>password_verify($password, $hash);</code></p>
  
  <p><strong>UPDATE</strong></p>
  
  <pre><code>&lt;?php
  require('db.php');
  
  if(isset($_POST['submit'])) {
    $stmt = $connect-&gt;prepare('SELECT user_name, user_password FROM `users` WHERE user_name = ?');
  
    if($stmt) {
      $username = $_POST['username'];
      $password = $_POST['password'];
  
      $stmt-&gt;bind_param('s', $username);
  
      $stmt-&gt;execute();
  
      // Get query results
      $result = $stmt-&gt;get_result();
  
      // Fetch the query results in a row
      while($row = $result-&gt;fetch_assoc()) {
        $hash = $row['user_password'];
        $username = $row['user_name'];
      }
  
      // Verify user's password $password being input and $hash being the stored hash
      if(password_verify($password, $hash)) {
        // Password is correct
      } else {
        // Password is incorrect
      }
  
    }
  }
  
  ?&gt;
  </code></pre>