title: PHP crypt password
body: <p>A simple Registration and login page for a website. I am trying to crypt the password + salting. That's what I have done but I am not sure if its correct.</p>
  
  <p>This is what happens in the registration page:</p>
  
  <pre><code>$blowfish = '$2a$10$';
  $salt = '8dF$d_3';
  $hashedPass = crypt($password,$blowfish . $salt);
  </code></pre>
  
  <p>In the database, the password "RAYray99" is stored as "$2a$10$8dF$d_3$$$$$$$$$$$$$$.wxsfa7X.nkcGqldJ9fujdd8eY.H85uC"</p>
  
  <hr>
  
  <p><strong>On the login page, I am stuck on how to check the password entered with the password in the database.</strong></p>
  
  <p>This is the loging php script that verifies the user:</p>
  
  <pre><code>mysql_connect("$db_host", "$db_username", "$db_pass") or die(mysql_error());
  //select the database or return error message
  mysql_select_db("$db_name") or die("database does not exist");
  
  $email = stripslashes($_POST['email']);
  $email = strip_tags($email);
  $email = mysql_real_escape_string($email);
  $password = ereg_replace("[^A-Za-z0-9]", "", $_POST['password']); // filter everything but numbers and letters
  $password = crypt($password);
  
  $sql = mysql_query("SELECT * FROM members WHERE email='$email' AND password='$password' AND activateemail='1'"); 
  $login_check = mysql_num_rows($sql);
  if($login_check &gt; 0){  
  while($row = mysql_fetch_array($sql)){ 
      // Get member ID into a session variable
      $id = $row["id"];   
      session_register('id'); 
      $_SESSION['id'] = $id;
      // Get member username into a session variable
      $username = $row["username"];   
      session_register('username'); 
      $_SESSION['username'] = $username;
      // Update last_log_date field for this member now
      mysql_query("UPDATE members SET lastlogin=now() WHERE id='$id'"); 
      // Print success message here if all went well then exit the script
      header("location: account.php"); 
      exit();
  } // close while
  
  } else {
  // Print login failure message to the user and link them back to your login page
    print '&lt;br /&gt;&lt;br /&gt;&lt;font color="#FF0000"&gt;ERROR TRY AGAIN &lt;/font&gt;&lt;br /&gt;;
    exit();
  }
  </code></pre>
  
  <p><strong>My question is how would I verify the login passsword entered on the login page with the 1 in the database.</strong></p>
  
  <p>Thank you,
  Ray</p>