title: PHP - Comparing hash with database is not working
body: <p>Notes:</p>
  
  <ul>
  <li>I'm still fairly new to php</li>
  <li>This login form seems to work perfectly fine if I don't hash the password.</li>
  <li>I've tried md5, sha256 and now I've left it at sha1. None of these work.</li>
  <li>I first used <code>echo sha1("password");</code> to find out what the hash for my password would be, I then copied that hash and pasted it manually with phpMyAdmin. I'm not sure if this is what the issue is or not.</li>
  </ul>
  
  <p>Anyways here is the code:</p>
  
  <pre><code>&lt;?php
  session_start();
  require("config.php");
  
  if(isset($_POST['submit'])) {
  
      $username = mysql_real_escape_string($_POST['username']);
      $password = sha1(mysql_real_escape_string($_POST['password']));
  
      $loginsql = "SELECT * FROM login WHERE username = '" . $username .
      "' AND password = '" . $password . "'";
      $loginresult = mysql_query($loginsql);
      $loginnumrows = mysql_num_rows($loginresult);
  
      if($loginnumrows == 1) {
          $loginrow = mysql_fetch_assoc($loginresult);
          session_register("USERNAME");
          session_register("USERID");
  
          $_SESSION['USERNAME'] = $loginrow['username'];
          $_SESSION['USERID'] = $loginrow['id'];
  
          header("Location: " . $config_basedir . "controlpanel.php");
      }
      else{
          echo "&lt;p&gt;Incorrect Login, please try again!&lt;/p&gt;";
      }
  }
  else{
  
  }
  ?&gt;
  </code></pre>
  
  <p>I'm really not too sure where to go with this. I'm sure my code could be more efficient but as I mentioned in the notes, it does work when I don't hash the password. Thank you for reading.</p>