title: Password_verify is not verifying the hash in the database
body: <p>I'm trying to log a user in but I get an error every time I try to verify the password. The username is verified just fine. My password is stored by password_hash in the database. For example, let's say I signup a username 'thisIsAUser' and the password is 'thisIsAUsersPassword'. The hash would be something like: <code>$2y$10$VR5FKZVLP6/43adb1PsGD.bsmrzp15jdftotz6xubDQtypZ1rKEFW</code>. The error would be the else statement of the if(password_verify). Notice that the else statement of the username not matching has a '.' at the end while the password not matching has a '!'.</p>
  <p>Logging in script:</p>
  <pre><code>&lt;?php 
  session_start();
              
  $link = mysqli_connect(&quot;localhost&quot;, &quot;root&quot;, &quot;Yuvraj123&quot;, &quot;KingOfQuiz&quot;);
  if(mysqli_connect_error()) {
      die(&quot;Couldn't connect to the database. try again later.&quot;);
  } 
      
  $query = &quot;SELECT * FROM `users`&quot;;
      
  if($result = mysqli_query($link, $query)) {
      $row = mysqli_fetch_array($result);
  }
              
  // define variables and set to empty values
  $loginSignupButton = &quot;&quot;;
  $loginUsername = &quot;&quot;;
  $loginPassword = &quot;&quot;;
         
  if ($_SERVER[&quot;REQUEST_METHOD&quot;] == &quot;POST&quot;) {
      $loginUsername = form_input($_POST[&quot;loginUsername&quot;]);
      $loginPassword = form_input($_POST[&quot;loginPassword&quot;]);
      $loginSignupButton = form_input($_POST[&quot;loginSignupButton&quot;]);
  }
      
  function form_input($data) {
      $data = trim($data);
      $data = stripslashes($data);
      $data = htmlspecialchars($data);
      return $data;
  }
          
  // define variables and set to empty values
  $loginUsernameError = &quot;&quot;;
  $loginPasswordError = &quot;&quot;;
  $error = &quot;&quot;;
  $loggingInUsername = &quot;&quot;;
  $unhashedPasswordThingyMajig = &quot;&quot;;
  if ($_SERVER[&quot;REQUEST_METHOD&quot;] == &quot;POST&quot;) {
      if (empty($_POST[&quot;loginUsername&quot;])) {
          $loginUsernameError = &quot;&lt;p style='color: red'&gt;Username is required&lt;/p&gt;&quot;;
          echo $loginUsernameError;
      } else {
          $loginUsername = form_input($_POST[&quot;loginUsername&quot;]);
      }
      if (empty($_POST[&quot;loginPassword&quot;])) {
          $loginPasswordError = &quot;&lt;p style='color: red'&gt;Password is required&lt;/p&gt;&quot;;
          echo $loginPasswordError;
      } else {
          $loginPassword = form_input($_POST[&quot;loginPassword&quot;]);
      }
      
      if($_POST['loginActive'] == &quot;0&quot;) {
                    
          $query = &quot;SELECT * FROM users WHERE username = '&quot;. mysqli_real_escape_string($link, $_POST['loginUsername']).&quot;' LIMIT 1&quot;; 
          $result = mysqli_query($link, $query);
          if(mysqli_num_rows($result) &gt; 0) {
              $error = &quot;&lt;p style='color: red'&gt;That username is already taken.&lt;/p&gt;&quot;;
              echo $error;
          } else {
              header ('location: signup.php');
          }
      } elseif($_POST['loginActive'] == &quot;1&quot;) {
          $sql = &quot;
                      SELECT *
                      FROM users
                      WHERE username = ?
                  &quot;; 
          $query  = mysqli_prepare($link, $sql);
          mysqli_stmt_bind_param($query, &quot;s&quot;, $_POST[&quot;loginUsername&quot;]);
          mysqli_stmt_execute($query);
          $result = mysqli_stmt_get_result($query);
                  
          if (mysqli_num_rows($result)) {
              $logInPassword = $_POST['loginPassword'];
              if(password_verify($logInPassword, $row['password'])) {
                  echo &quot;Hello World!&quot;;
              } else {
                  $error = &quot;&lt;p style='color: red'&gt; The Password and Username combination Is not Valid!&lt;/p&gt;&quot;;
                  echo $error;
              }
          } else {
              $error = &quot;&lt;p style='color: red'&gt; The Password and Username combination Is not Valid.&lt;/p&gt;&quot;;
              echo $error;
          }   
      } 
  }
  ?&gt;
  </code></pre>
  <p>Form(This is the logging in one, not the signup):</p>
  <pre><code>&lt;div class=&quot;modal fade&quot; id=&quot;exampleModal&quot; tabindex=&quot;-1&quot; aria-labelledby=&quot;exampleModalLabel&quot; aria-hidden=&quot;true&quot;&gt;
    &lt;div class=&quot;modal-dialog&quot;&gt;
      &lt;div class=&quot;modal-content&quot;&gt;
        &lt;div class=&quot;modal-header&quot; id=&quot;LoginModalTitle&quot;&gt;
          &lt;h5 class=&quot;modal-title&quot; id=&quot;exampleModalLabel LoginModalTitle&quot;&gt;Login&lt;/h5&gt;
          &lt;button type=&quot;button&quot; class=&quot;close&quot; data-dismiss=&quot;modal&quot; aria-label=&quot;Close&quot;&gt;
            &lt;span aria-hidden=&quot;true&quot; style=&quot;color: white&quot;&gt;&amp;times;&lt;/span&gt;
          &lt;/button&gt;
        &lt;/div&gt;
        &lt;div class=&quot;modal-body&quot;&gt;
          &lt;form method=&quot;post&quot; action=&quot;&lt;?php echo htmlspecialchars($_SERVER[&quot;PHP_SELF&quot;]);?&gt;&quot; id=&quot;modal-details&quot;&gt;
        &lt;div class=&quot;form-group&quot;&gt;
          &lt;input type=&quot;hidden&quot; id=&quot;loginActive&quot; name=&quot;loginActive&quot; value=&quot;1&quot;&gt;
          &lt;label for=&quot;loginUsername&quot;&gt;Username&lt;/label&gt;
          &lt;input type=&quot;text&quot; class=&quot;form-control formInput&quot; id=&quot;inputUsername&quot; placeholder=&quot;Eg: RealKingOfQuiz&quot; name=&quot;loginUsername&quot; autocomplete=&quot;off&quot; required&gt;
          &lt;p&gt;&lt;span class=&quot;error&quot;&gt;&lt;?php echo $loginUsernameError;?&gt;&lt;/span&gt;&lt;p&gt;
        &lt;/div&gt;
        &lt;div class=&quot;form-group&quot;&gt;
          &lt;label for=&quot;loginPassword&quot;&gt;Password&lt;/label&gt;
          &lt;input type=&quot;password&quot; class=&quot;form-control formInput&quot; id=&quot;inputPassword&quot; name=&quot;loginPassword&quot; required autocomplete=&quot;on&quot;&gt;
          &lt;small&gt;&lt;a href=&quot;&quot; id=&quot;forgotPassword&quot; style=&quot;color: blue; text-decoration: none&quot;&gt;Forgot Password?&lt;/a&gt;&lt;/small&gt;
          &lt;p&gt;&lt;span class=&quot;error&quot;&gt;&lt;?php echo $loginPasswordError;?&gt;&lt;/span&gt;&lt;/p&gt;
        &lt;/div&gt;
          &lt;p&gt;&lt;span class=&quot;error&quot;&gt;&lt;?php echo $error;?&gt;&lt;/span&gt;&lt;/p&gt;
          &lt;div class=&quot;alert alert-danger&quot; id=&quot;loginAlert&quot;&gt;&lt;/div&gt;
          &lt;/form&gt;
        &lt;/div&gt;
        &lt;div class=&quot;modal-footer&quot;&gt;
          &lt;a id=&quot;toggleLogin&quot;&gt;Sign Up?&lt;/a&gt;
          &lt;button type=&quot;button&quot; class=&quot;btn btn-secondary&quot; data-dismiss=&quot;modal&quot;&gt;Cancel&lt;/button&gt;
          &lt;button class=&quot;btn btn-success&quot; id=&quot;LoginSignUpButton&quot; name=&quot;loginSignupButton&quot; form=&quot;modal-details&quot; disabled&gt;Login&lt;/button&gt;
          &lt;/div&gt;
      &lt;/div&gt;
    &lt;/div&gt;
  &lt;/div&gt;
  </code></pre>