可能重复:
PHP 密码的安全哈希和盐
我正在为我的网站编写一个 PHP 脚本,它自己的网站已经启动并正在运行。我遇到的问题是网站上的注册是纯文本密码。显然,这是非常弱的安全性。我希望有人可以帮我转换它,以便我可以使用哈希密码。我已经包含了我认为重要的部分注册码。我没有在页面上包含所有代码,因为我认为它不相关,但如果有人认为它会有所帮助,我会提供。
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()."<br>";
            if (!$usercheck) {
       $err_msg = "Database error:<br>There was an error entering your account.<br>It is possible that username or Email already exists, please try another one.<br>";
         }   else {
            include ("reg.php"); 
            exit;
            }
     }
     if (!$err_msg) {
        // done, you are entered correctly
     }
   pageHeader($title, $bgColor, $styleSheet);
?>