SA-MP Forums Archive
[PHP] Sha256 password not same as one generated by SAMP - Printable Version

+- SA-MP Forums Archive (https://sampforum.blast.hk)
+-- Forum: SA-MP Scripting and Plugins (https://sampforum.blast.hk/forumdisplay.php?fid=8)
+--- Forum: Scripting Help (https://sampforum.blast.hk/forumdisplay.php?fid=12)
+--- Thread: [PHP] Sha256 password not same as one generated by SAMP (/showthread.php?tid=638516)



[PHP] Sha256 password not same as one generated by SAMP - seanny - 02.08.2017

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");
            }*/
        
}
    }
}
?>



Re: [PHP] Sha256 password not same as one generated by SAMP - Paulice - 02.08.2017

Change "&&" to "AND" in your SQL statement.

-----

They do return the same hash:



Re: [PHP] Sha256 password not same as one generated by SAMP - seanny - 02.08.2017

Quote:
Originally Posted by Paulice
Посмотреть сообщение
Change "&&" to "AND" in your SQL statement.

-----

They do return the same hash:
I've changed && to AND.

I dunno why it's returning a different hash on my system then. I'll need to look into it more.


Re: [PHP] Sha256 password not same as one generated by SAMP - Banditul18 - 02.08.2017

When i was trying to do the same, for me php returned a lower case hash but samp was returned a uper case case. So they never match unless. So use strtoupper on the php hash.
This was my problem, i dunno if will work for you....


Re: [PHP] Sha256 password not same as one generated by SAMP - Paulice - 02.08.2017

Quote:
Originally Posted by Banditul18
Посмотреть сообщение
When i was trying to do the same, for me php returned a lower case hash but samp was returned a uper case case. So they never match unless. So use strtoupper on the php hash.
This was my problem, i dunno if will work for you....
Look at his code...


Re: [PHP] Sha256 password not same as one generated by SAMP - dboz - 03.08.2017

I got this same problem. Help


Re: [PHP] Sha256 password not same as one generated by SAMP - Thomas. - 03.08.2017

You should post the code of the gamemode side as well. Since they produce different results, we need to be able to compare what these scripts are doing.