An implementation of bcrypt password hashing library for Pawn, written in C/C++.
- All passwords are automatically salted
- Bcrypt is slow, which makes offline bruteforce attacks less efficient
- The work factor can be increased as the computers become more powerful
bcrypt_hash(const key[], cost = 12, const callback_name[], const callback_format[] = "", {Float, _}:...);bcrypt_check(const password[], const hash[], const callback_name[], const callback_format[] = "", {Float, _}:...);bcrypt_get_hash(dest[]);bcrypt_is_equal();bcrypt_needs_rehash(const hash[], cost);bcrypt_find_cost(time_target = 250);bcrypt_set_thread_limit(value);bcrypt_debug(BCRYPT_DEBUG_LEVEL:level = BCRYPT_LOG_ERROR);
See the wiki for detailed usage.
- Copy
bcrypt-samp.soto thepluginsfolder - Add
plugins bcrypt-samp.soto server.cfg - Copy
bcrypt.incto the compiler's include directory (pawno/includeby default) - Add
#include <bcrypt>to your gamemode or filterscript
- Copy
bcrypt-samp.dllto thepluginsfolder - Add
plugins bcrypt-sampto server.cfg - Copy
bcrypt.incto the compiler's include directory (pawno/includeby default) - Add
#include <bcrypt>to your gamemode or filterscript
-
Call function
bcrypt_hashwhen you would like to hash user input (e.g. on registration, or when updating the work factor). Once the hash is calculated, the callback defined in the parameters will be called, and the hash can be acquired usingbcrypt_get_hashfunction -
Call function
bcrypt_checkwhen you would like to verify whether or not user input matches a given hash (e.g. on login). Once the verification is done, the callback defined in the parameters will be called, and the result can be acquired usingbcrypt_is_equalfunction -
You can use
bcrypt_needs_rehashto check whether or not the hash needs to be updated -
If you would like to override the default number of threads used, you may use function
bcrypt_set_thread_limit. In most cases, however, the default value is adequate
#include <a_samp>
#include <bcrypt>
#define BCRYPT_COST 12
forward OnPasswordHashed(playerid);
forward OnPasswordChecked(playerid);
public OnDialogResponse(playerid, dialogid, response, listitem, inputtext[])
{
switch(dialogid)
{
case DIALOG_REGISTRATION:
{
bcrypt_hash(inputtext, BCRYPT_COST, "OnPasswordHashed", "d", playerid);
}
case DIALOG_LOGIN:
{
// Variable hash is expected to contain the hash loaded from the database
bcrypt_check(inputtext, hash, "OnPasswordChecked", "d", playerid);
}
}
return 1;
}
public OnPasswordHashed(playerid)
{
new hash[BCRYPT_HASH_LENGTH];
bcrypt_get_hash(hash);
printf("Password hashed for player %d: %s", playerid, hash);
return 1;
}
public OnPasswordChecked(playerid)
{
new bool:match = bcrypt_is_equal();
printf("Password checked for %d: %s", playerid, (match) ? ("Match") : ("No match"));
return 1;
}