2016-03-02 106 views
-1

我有SA-MP如何使用SHA256加鹽?

new MyHash[256]; 
SHA256_PassHash(inputtext, "78sdjs86d2h", MyHash, sizeof(MyHash)); 
if(!strcmp(MyHash, PlayerInfo[playerid][pKey])) 

的哈希函數我認爲78sdjs86d2h是鹽,但我要如何設置PHP的鹽?

我正在使用這段代碼,它是哈希函數而不是我的鹽。

if(isset($_POST['username']) && isset($_POST['password'])){ 

    mysql_query('SET NAMES utf8'); 
    $var = mysql_real_escape_string("\xbf\x27 OR 1=1 /*"); 

    $username = mysql_real_escape_string($_POST['username']); 
    $parola = mysql_real_escape_string($_POST['password']); 
    $hash = hash('sha256', $parola); 

    $check = get_row("SELECT ID FROM players WHERE Name='$username' && password='$hash' LIMIT 1"); 
    if(isset($check['ID'])) 
    { 
     $_SESSION['username'] = $_POST['username']; 
     $_SESSION['password'] = $_POST['password']; 
     $id = $check['ID']; 
     header("location: index.php"); 
    } 
    else 
    { 
     printf("%s", $hash); 
     $err = 'Username sau parola incorecte'; 
    } 
} 

我該如何使用我自己的鹽做散列?

+0

我強烈建議使用[password_hash(http://php.net/manual/en/function。 password-hash.php),[使用mysqli或pdo代替mysql](http://stackoverflow.com/questions/12859942/why-shouldnt-i-use-mysql-functions-in-php)。 –

回答

-1

更新:試過這樣

$username = mysqli_real_escape_string($DB_H, addslashes($_POST['username'])); 
$password1 = $_POST['password']; 
$salt  = '78sdjs86d2h'; 
$parola = hash('sha256', $password1 . $salt); 

結果:33ca067dc70ef75fc1a1107f4345f3a819ecca657d3d9646d26822fd691cd10c 原:BFD2832240F5FC1FD12004634EBE9FDE97BD0D4690695DFAC1350D0AE037398F