[PHP] Sha256 password not same as one generated by SAMP
#1

I am creating a User Control Panel in PHP for use with alongside a SAMP gamemode. The gamemode is fine, but when I try to create the login system on the UCP, the password generated by PHP does not match the salted one generated by SAMP (SHA256_PassHash).

PHP код:
<?php
require_once("config.php");
if(
$_SERVER["REQUEST_METHOD"] == "POST"
{
    
// username and password sent from form 
    
$myusername mysqli_real_escape_string($conn,$_POST['Username']);
    
$mypassword mysqli_real_escape_string($conn,$_POST['password']); 
    
$sql "SELECT * FROM `users` WHERE `name` = '".$myusername."' LIMIT 1";
    
$result mysqli_query($conn$sql);
    if (
mysqli_num_rows($result) > 0)
    {
        while(
$arow mysqli_fetch_assoc($result)) 
        {
            
$salt $arow["salt"];
            
$hash1 hash('sha256'$mypassword $salt);
            
$hash strtoupper($hash1);
            
$check "SELECT * FROM users WHERE name='$myusername' && password = '$hash'";
            
$result mysqli_query($conn,$check);
            
$row mysqli_fetch_array($result,MYSQLI_ASSOC);
            
$count mysqli_num_rows($result);
            echo 
"DEBUG: db pass = ".$arow["password"]."<br>";
            echo 
"DEBUG: php pass = ".$hash;
            
/*if(strcmp($arow["password"],$hash) == 0)
            {
                $_SESSION['username'] = $myusername;
                header("location: index.php");
            }
            else 
            {
                header("location: login.php?error=1&password=$password");
            }*/
        
}
    }
}
?>
Reply


Messages In This Thread

Forum Jump:


Users browsing this thread: 1 Guest(s)