跳到主要內容

SHA256_PassHash

注意

此函式於 SA-MP 0.3.7 R1 版本中新增,在更早的版本中無法使用!

注意

This function is deprecated in open.mp, Use samp-bcrypt plugin for hashing.

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.

NameDescription
const password[]The password to hash.
const salt[]The salt to use in the hash.
output[]The returned hash in uppercase hexadecimal digest.
size = sizeof (output)The returned hash maximum length.

Returns​

The hash is stored in the specified array.

Examples​

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

Good to know​

備註

The returned hash has zero padding (i.e. possible prefix 00ABCD123...).

技巧
  • 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.
注意

This function is not binary-safe. Using binary values on password and salt might give unexpected result.