Account PHP: Difference between revisions
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...") |
ThePiotrek (talk | contribs) mNo edit summary |
||
(2 intermediate revisions by one other user not shown) | |||
Line 1: | Line 1: | ||
=Check MTA server | ==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> | ||
[[pl:Account PHP]] |
Latest revision as of 13:50, 4 October 2016
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; }