title: How do I encrypt this password with MD5 using PHP?
body: <p>The code below is from a login script, written in PHP. The database that it checks passwords against encrypts the passwords using MD5 however when the login script checks against the database for a password, it is checking the raw password without encryption. I am familiar with the md5() function but how would I incorporate that into the following:</p>
  
  <pre><code>&lt;?php
  session_start();
  
  $username = $_POST['username'];
  $password = $_POST['password'];
  
  if ($username &amp;&amp; $password) {
      $connect = mysql_connect("host", "user", "password") or die("Couldn't connect");
      mysql_select_db("dbname") or die("Couldn't find the database");
  
      $query = mysql_query("SELECT * FROM users WHERE username='$username'");
      $numrows = mysql_num_rows($query);
  
      if ($numrows != 0) {
          while ($row = mysql_fetch_assoc($query)) {
              $dbusername = $row['username'];
              $dbpassword = $row['password'];
          }
  
          if ($username == $dbusername &amp;&amp; $password == $dbpassword) {
              echo "You're in! Click &lt;a href='../member.php'&gt;here&lt;/a&gt; to enter the member page.";
              $_SESSION['username'] = $username;
          }else{
              echo "Incorrect password";
          }
      }else{
          die("That username does not exist.");
      }
  }else{
      die("Please enter a valid username and password.");
  }
  ?&gt;
  </code></pre>