SHA256 PassHash

From SA-MP Wiki

Jump to: navigation, search

SHA256_PassHash

This function was added in SA-MP 0.3.7 R1 and will not work in earlier versions!


Description:

Hashes a password using the SHA-256 hashing algorithm. Includes a salt. The output is always 256 bytes in length, or the equivalent of 64 Pawn cells.


Parameters:
(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.
ret_hash_lenThe returned hash maximum length.


Return Values:

This function does not return any specific values.


Tips

Image:Light_bulb_icon.png

  • The salt is appended to the end of the password, meaning password 'foo' and salt 'bar' would form 'foobar'.
  • The salt should be random, unique for each player and at least as long as the hashed password. It is to be stored alongside the actual hash in the player's account.


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);
    return 1;
}
Personal tools
Navigation
Toolbox