Skip to content

MySQL_VerifyPassword

imshooter edited this page Oct 24, 2026 · 1 revision

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.

The public takes (context, bool:match). A hash that cannot be read never matches, and the reason is logged. Verifying costs what the hash cost.

native bool:MySQL_VerifyPassword(const password[], const hash[], const callback[], context = 0);

Parameters

Parameter Description Default
const password[] The password.
const hash[] The hash, from MySQL_HashArgon2, MySQL_HashBcrypt or any other Argon2 or bcrypt library.
const callback[] Public to call.
context Value the public receives. 0

Returns

  • true when the work started.
  • false when callback is not a public of the script.

Remarks

It reads the costs and the salt from the hash, so hashes made with other costs, by other programs or by older versions of a script verify the same. Argon2id, Argon2i and Argon2d, and bcrypt $2a$, $2b$, $2x$ and $2y$ are read. The comparison takes the same time whether the password matches or not.

Example

forward OnPasswordChecked(playerid, bool:match);

stock CheckPassword(playerid, const password[], const hash[]) {
    MySQL_VerifyPassword(password, hash, "OnPasswordChecked", playerid);
}

public OnPasswordChecked(playerid, bool:match) {
    if (!match) {
        return SendClientMessage(playerid, -1, "Wrong password.");
    }

    SpawnPlayer(playerid);

    return 1;
}

Related

  • MySQL_HashArgon2: Hash a password with Argon2id on a thread of the component, and call a public with context and the hash.
  • 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