Skip to content

MySQL_HashArgon2

imshooter edited this page Oct 24, 2026 · 1 revision

Hash a password with Argon2id on a thread of the component, and call a public with context and the hash.

The public takes (context, const hash[]). The hash is empty when it failed, and the reason is logged. It holds its salt and costs, so MySQL_VerifyPassword needs nothing else, and a hash made with other costs still verifies.

native bool:MySQL_HashArgon2(
    const password[],
    const callback[],
    context = 0,
    memory = MYSQL_ARGON2_MEMORY,
    iterations = MYSQL_ARGON2_ITERATIONS,
    parallelism = MYSQL_ARGON2_PARALLELISM
);

Parameters

Parameter Description Default
const password[] The password.
const callback[] Public to call.
context Value the public receives. 0
memory Memory, in KiB, from 8192 to 1048576. MYSQL_ARGON2_MEMORY
iterations Passes, from 1 to 16. MYSQL_ARGON2_ITERATIONS
parallelism Lanes, from 1 to 8. MYSQL_ARGON2_PARALLELISM

Returns

  • true when the work started.
  • false when a cost is out of range, or callback is not a public of the script.

Remarks

The work runs on two threads of the component, apart from the connections, and the public is called on a later server tick. The hash is in the encoded form of Argon2, with its costs and salt, as $argon2id$v=19$m=19456,t=2,p=1$..., and fits in MYSQL_HASH_LENGTH characters. The defaults are the least costs OWASP recommends. See Passwords.

Example

new MySQL:gDatabase;

forward OnPasswordHashed(playerid, const hash[]);

stock Register(playerid, const password[]) {
    MySQL_HashArgon2(password, "OnPasswordHashed", playerid);
}

public OnPasswordHashed(playerid, const hash[]) {
    new
        name[MAX_PLAYER_NAME + 1]
    ;

    if (hash[0] == EOS) {
        return SendClientMessage(playerid, -1, "The password could not be secured.");
    }

    GetPlayerName(playerid, name, sizeof (name));
    MySQL_Send(gDatabase, "INSERT INTO accounts (name, hash) VALUES (%q, %q)", name, hash);

    return 1;
}

Related

  • MySQL_VerifyPassword: Verify a password against an Argon2 or bcrypt hash on a thread of the component, and call a public with context and whether they match.
  • MySQL_HashBcrypt: Hash a password with bcrypt, as $2b$, on a thread of the component, and call a public with context and the hash.

Clone this wiki locally