Account PHP: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
(Created page with "=Check MTA server accounts database password== This php function will return true if the password matches the hash from the accounts database <syntaxhighlight lang="lua"> function passwordMatch( $plai...")
 
No edit summary
Line 1: Line 1:
=Check MTA server accounts database password==
=Check MTA server accounts=
This php function will return true if the password matches the hash from the accounts database
This php function will return true if the password matches the hash from the accounts database
<syntaxhighlight lang="lua">
<syntaxhighlight lang="lua">

Revision as of 07:18, 18 November 2013

Check MTA server accounts

This php function will return true if the password matches the hash from the accounts database

function passwordMatch( $plain, $hash )
{
	//-- Empty passwords never match
	if ( $plain == "" || $hash == "" )
		return false;

	if ( strlen($hash) == 64 + 32 + 1 )
	{
		//-- SHA256 + type + salt
		$strSha256 = substr( $hash, 0, 64 );
		$strType = substr( $hash, 64, 1 );
		$strSalt = substr( $hash, 65, 32 );

		//-- Password hash was generated from MD5, so do the same thing for the test
		if ( $strType == "1" )
			$plain = strtoupper(md5($plain));

		$strPasswordHashed = strtoupper(hash( "sha256", $strSalt . $plain ));
		return $strPasswordHashed == $strSha256;
	}
	else
	if ( strlen($hash) == 32 )
	{
		//-- MD5
		return strtoupper(md5($plain)) == $hash;
	}
}