Skip to content

Commit e702c03

Browse files
committed
Add missing account PHP code
1 parent ac8c2a6 commit e702c03

File tree

1 file changed

+38
-1
lines changed

1 file changed

+38
-1
lines changed

elements/Account/account.yaml

Lines changed: 38 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,5 +6,42 @@ description: |
66
77
When a user logs in or out, the account object assigned to them will change. As such, you must not assume that the account attached to a client remains constant during their session.
88
9-
PHP code to check password hashes from the MTA server database is [here](/Account_PHP).
9+
PHP code to check password hashes from the MTA server database is
10+
11+
<details>
12+
<summary>Here</summary>
13+
This php function will return true if the password matches the hash from the accounts database.
14+
15+
```php
16+
function passwordMatch( $plain, $hash )
17+
{
18+
//-- Empty passwords never match
19+
if ( $plain == "" || $hash == "" )
20+
return false;
21+
22+
if ( strlen($hash) == 64 + 32 + 1 )
23+
{
24+
//-- SHA256 + type + salt
25+
$strSha256 = substr( $hash, 0, 64 );
26+
$strType = substr( $hash, 64, 1 );
27+
$strSalt = substr( $hash, 65, 32 );
28+
29+
//-- Password hash was generated from MD5, so do the same thing for the test
30+
if ( $strType == "1" )
31+
$plain = strtoupper(md5($plain));
32+
33+
$strPasswordHashed = strtoupper(hash( "sha256", $strSalt . $plain ));
34+
return $strPasswordHashed == $strSha256;
35+
}
36+
else
37+
if ( strlen($hash) == 32 )
38+
{
39+
//-- MD5
40+
return strtoupper(md5($plain)) == $hash;
41+
}
42+
return false;
43+
}
44+
```
45+
46+
</details>
1047

0 commit comments

Comments
 (0)