title: PHP salt and hash SHA256 for login password
body: <p>I've made encrypting of the password in my register script and they are stored in the database, and I have to use them to login, so I would want to use the unencrypted ones to login. I've read some of the threads in here but nothing is helping me. How can I add it in my login.php? The salt is also stored in the database.</p>
  
  <p>This is my register.php script for encrypting</p>
  
  <pre><code>$hash = hash('sha256', $password1);
  
  function createSalt()
  {
      $text = md5(uniqid(rand(), TRUE));
      return substr($text, 0, 3);
  }
  
  $salt = createSalt();
  $password = hash('sha256', $salt . $hash);
  </code></pre>
  
  <p>and this is my login.php with season</p>
  
  <pre><code>//Create query
  $qry="SELECT * FROM member WHERE username='$username' AND password='$password'";
  $result=mysql_query($qry);
  
  //Check whether the query was successful or not
  if($result) {
      if(mysql_num_rows($result) &gt; 0) {
          //Login Successful
          session_regenerate_id();
          $member = mysql_fetch_assoc($result);
          $_SESSION['SESS_MEMBER_ID'] = $member['id'];
          $_SESSION['SESS_FIRST_NAME'] = $member['username'];
          $_SESSION['SESS_LAST_NAME'] = $member['password'];
          session_write_close();
          header("location: profile.php");
          exit();
      }
      else {
          //Login failed
          //error message 
      }
  else {
      die("Query failed");
  }
  </code></pre>