title: convert plain text password login to hash
body: <blockquote>
    <p><strong>Possible Duplicate:</strong><br>
    <a href="https://stackoverflow.com/questions/401656/secure-hash-and-salt-for-php-passwords">Secure hash and salt for PHP passwords</a>  </p>
  </blockquote>
  
  
  
  <p>I am working on a PHP script for my site, the site it's self is up and running. The problem I have is that the registration on the website is for plain text passwords. Obviously this is very weak security. I am hoping someone can help me convert it so I can use a hash password.
  I have included part of the registration code that I think counts. I did not include all code on the page as I did not think it relevant but will supply if someone thinks it will help.</p>
  
  <pre><code>require 'include.inc';
  if ($signup) {
  
  if ($signup[repassword] != $signup[password]) {
      $err_msg = "Your passwords do not match.";
  error($err_msg);
  }
  
  if(!preg_match("^[_\.0-9a-z-]+$/i^", $str)) {
  $msg = 'Invalid Username! Usernames can consist of letters and numbers only';
  }
  if(!preg_match("^[_\.0-9a-z-]+$^",$signup[password])) {
     $err_msg = "Invalid Password!  Passwords can consist of letters and numbers   only.";
  }
    if(!$signup[password] || !$signup[username] || !$signup[email] || !$signup[username])
          $err_msg = "Oops! You forgot some important fields!";
  
  
    if (!$err_msg) {
  $usercheck = @mysql_query("INSERT INTO user values(
      'NULL','$signup[fname]','$signup[lname]',
      '$signup[username]','$signup[password]','$signup[email]', 1, ".$pointInc.",     '$signup[referral]', NOW(), 'n', 'y')");
  
        // done, you are entered correctly, Now Enter the points and URL info
  
  
          $sql = "Select id from user where username='$signup[username]'";
  
      $result = mysql_query( $sql );
          if ( $result != false )
              {
          while ( $data = mysql_fetch_assoc( $result ) )
          {
              $point_set = $data['id'];
  
              }
          } else {
              echo mysql_error();
          }   
      // add rerral points
  
  if ($signup[referral])  {
    $referralSql="UPDATE points SET points=points+ ".$refPoints . " WHERE     userid=".$signup[referral];
    $result = mysql_query( $referralSql );
                  if ( $result != false )
                      {
                  } else {
                      echo mysql_error();
                      }
      }                           
  
  
  // add URL  
  
  $sql="INSERT INTO url_table ( userid, website, active, datechanged) VALUES ($point_set,'".$signup[site_url]."','n', '".date("Ymd")."')";
  
    $result = mysql_query( $sql );
                  if ( $result != false )
                      {
                  } else {
                      echo mysql_error();
                  }
  // add points
      $sql="INSERT INTO points (userid, username, points) VALUES ($point_set,'     ',$signPoints)";
    $result = mysql_query( $sql );
                  if ( $result != false )
                      {
                  } else {
                      echo mysql_error();
                      }
      }
       echo mysql_errno().": ".mysql_error()."&lt;br&gt;";
  
  
  
  
  
              if (!$usercheck) {
         $err_msg = "Database error:&lt;br&gt;There was an error entering your account.&lt;br&gt;It is possible that username or Email already exists, please try another one.&lt;br&gt;";
           }   else {
              include ("reg.php"); 
              exit;
              }
       }
       if (!$err_msg) {
          // done, you are entered correctly
  
  
  
       }
     pageHeader($title, $bgColor, $styleSheet);
  ?&gt;
  </code></pre>