Account PHP: Difference between revisions

From Multi Theft Auto: Wiki
Jump to navigation Jump to search
No edit summary
No edit summary
Line 1: Line 1:
=Check MTA server accounts=
==Check MTA server account==
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">
Line 28: Line 28:
return strtoupper(md5($plain)) == $hash;
return strtoupper(md5($plain)) == $hash;
}
}
return false;
}
}
</syntaxhighlight>
</syntaxhighlight>

Revision as of 07:19, 18 November 2013

Check MTA server account

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;
	}
	return false;
}