SA-MP Forums Archive
Different results for PHP/Pawn Adler32 hash - 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: Different results for PHP/Pawn Adler32 hash (/showthread.php?tid=174328)



Different results for PHP/Pawn Adler32 hash - Peppe95 - 05.09.2010

I'm making a PHP User Control Panel for my gamemode.
In my gm I use this function to hash passwords:
Код:
stock num_hash(buf[])
 {
	new length=strlen(buf);
    new s1 = 1;
    new s2 = 0;
    new n;
    for (n=0; n<length; n++) {
       s1 = (s1 + buf[n]) % 65521;
       s2 = (s2 + s1)     % 65521;
    }
    return (s2 << 16) + s1;
 }
and in php to crypt strings I converted this function to:
Код:
<?php

    function num_hash($buf) 
    {
        $length=strlen($buf);
        $s1 = 1;
        $s2 = 0;
        $n = 0;
        for ($n; $n<$length; $n++) 
		{
           $s1 = ($s1 + $buf[$n]) % 65521;
           $s2 = ($s2 + $s1)  % 65521;
        }
        return ($s2 << 16) + $s1;
    }
    
?>
But the two functions generate different results! Why? These functions seem to be equals...

Php strings are different than pawn strings?


Re: Different results for PHP/Pawn Adler32 hash - tjying95 - 05.09.2010

Try to use this code for your php...
Код:
function num_hash($pass)
{
	$length = strlen($pass);
	$s1 = 1;
	$s2 = 0;
	    
	for($i=0; $i<$length; $i++)
	{
		$s1 = ($s1 + ord($pass[$i])) % 65521;
		$s2 = ($s2 + $s1)       % 65521;
	}
	$wy= ($s2 << 16) + $s1;
	return $wy;
}
It should give the same result as the pawn one.


Re: Different results for PHP/Pawn Adler32 hash - Peppe95 - 05.09.2010

Thanks very much *.* It works D:


Re: Different results for PHP/Pawn Adler32 hash - Calgon - 05.09.2010

Quote:
Originally Posted by ******
Посмотреть сообщение
Don't use Adler32 - it is not a secure hash algorithm! Both PAWN and PHP support Whirlpool, which IS secure!
Beat me to it, I just started using whirlpool w/ PHP earlier today. A quick example with whirlpool in PHP:
PHP код:
<?php
echo hash('whirlpool''4kasgkamklsgamklsgmkl');
?>
Easier to use than Adler32 and probably 100x more secure.


Re: Different results for PHP/Pawn Adler32 hash - Mattos - 19.11.2011

And how to decript the password?


Re: Different results for PHP/Pawn Adler32 hash - System64 - 19.11.2011

use md5 or whirpool, I use md5 'cause it's integrered in PHP and in MySQL plugin for samp!


Re: Different results for PHP/Pawn Adler32 hash - Calgon - 19.11.2011

Quote:
Originally Posted by Mateuscm
Посмотреть сообщение
And how to decript the password?
Once a password is encrypted in Whirlpool, there is no way at all, to decrypt it. If you want to check that someone entered their password correctly, you need to encrypt what they're trying as the password, and compare the encrypted value against the already stored encrypted password.