SHA256 PassHash
From SA-MP Wiki
(Difference between revisions)
Revision as of 05:47, 18 November 2019 RoboN1X (Talk | contribs) (warning about null terminated params) ← Previous diff |
Current revision RoboN1X (Talk | contribs) (zero padding) |
||
Line 14: | Line 14: | ||
* The hash is stored in the specified array.}} | * The hash is stored in the specified array.}} | ||
- | {{Warning|This function is not binary-safe. Using binary values on '''password''' and '''salt''' might give unexpected result}} | + | {{Warning|This function is not binary-safe. Using binary values on '''password''' and '''salt''' might give unexpected result.}} |
+ | |||
+ | {{Note|The returned hash has zero padding (i.e. possible prefix ''00ABCD123...'').}} | ||
{{Tips| | {{Tips| |
Current revision
[edit]
SHA256_PassHash
Description:
Hashes a password using the SHA-256 hashing algorithm. Includes a salt. The output is always 256 bits in length, or the equivalent of 64 Pawn cells.
(password[], salt[], ret_hash[], ret_hash_len)
password[] | The password to hash. |
salt[] | The salt to use in the hash. |
ret_hash[] | The returned hash in uppercase hexadecimal digest. |
ret_hash_len | The returned hash maximum length. |
Return Values:
The length of the hash string (64 bytes).
- The hash is stored in the specified array.
Warning | This function is not binary-safe. Using binary values on password and salt might give unexpected result. |
Tips |
|
Example Usage:
public OnGameModeInit() { new MyHash[64 + 1]; // + 1 to account for the required null terminator SHA256_PassHash("test", "78sdjs86d2h", MyHash, sizeof MyHash); printf("Returned hash: %s", MyHash); // Returned hash: CD16A1C8BF5792B48142FF6B67C9CB5B1BDC7260D8D11AFBA6BCDE0933A3C0AF return 1; }