[Plugin] Bcrypt
#1

Bcrypt for SA-MP

Latest release: v2.2.3 (Jan 31, 2015)


Downloads
Source code
Wiki
Change log
Introduction

Bcrypt is a hash function designed particularly for passwords, which implements an
automatic salt on all passwords, and allows the work factor to be changed as the computers
become more powerful.

Bcrypt is widely recommended, and often considered as the most secure method for hashing passwords. Source

Benefits
  • All passwords are automatically salted.

  • Bcrypt is slow, which makes offline bruteforce attacks very hard (depends on the work factor).

  • The work factor can be increased as the computers become more powerful.

  • The plugin is multi threaded, so the impact on server performance is negligible.

  • Compatible with PHP's password_verify() and password_hash() functions.
Installation

With sampctl

Code:
sampctl package install lassir/bcrypt-samp:v2.2.3
Alternatively
  • Download the latest version of the plugins here.
  • Copy the plugin file and the include file to their appropriate directories
Usage
  • Include the .inc file in your filterscript or gamemode (#include <bcrypt>)

  • Call function bcrypt_check when you would like to verify whether or not user input matches a given
    hash (e.g. on login). Once the verification is done, the defined callback will be called, and the
    result can be acquired by calling function bcrypt_is_equal() in the callback.

  • If you ever change the cost, you may use bcrypt_needs_rehash function to check if the hash in the
    database should be updated. The function returns true if the hash should be rehashes, and false if the
    hash is up-to-date.
Functions Hash

Function bcrypt_get_hash returns the result from bcrypt_hash, which is a 61-character-long string
(60 + null terminator), which is also defined as constant BCRYPT_HASH_LENGTH.

Below is the output for hashing "Hello World!" three times. The hash is completely unique every time,
because a random salt is used when calculating the hash every time.
Code:
1. $2y$12$33T1WbJGYD9YVKpBShTDsOOlS3248tApLCndjz28n0cyWZR1HYXy6
2. $2y$12$ExnQyld7o8w0QbWmAJgsJuygOwlFlbMITgzuw9g.6jbnscTd5kSK6
3. $2y$12$ivsAFLaGM52oCZnFe/QKBuoJy0osV8UsbJODPBUxeY3XSBhr739Yi
Cost

Cost represents the work factor, which is proportional to the amount of time it takes to calculate a
hash, and thus how secure the hash is. Increasing the cost by one approximately doubles the time
required to calculate the hash. Cost 10-13 should be adequate for most servers. The range of allowed
values for the cost is 4-31.

Example

pawn Code:
#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;
}
Trouble shooting

Problem:
The program can’t start because MSVCR120.dll is missing from your computer.

Solution:
Please download and install the 32-bit version of Visual C++ Redistributable Packages for Visual Studio 2013 (vcredist_x86.exe).

Credits
  • Johnson_boy
  • maddinat0r
Reply


Messages In This Thread
Bcrypt (Password hash) - by Johnson_boy - 25.07.2013, 12:59
AW: Bcrypt - by Poket-Jony - 25.07.2013, 13:02
Re: Bcrypt - by Djole1337 - 25.07.2013, 13:17
Re: Bcrypt - by roschti - 25.07.2013, 13:52
AW: Bcrypt - by BigETI - 25.07.2013, 14:24
Re: Bcrypt - by Johnson_boy - 25.07.2013, 14:30
Re: Bcrypt - by Johnson_boy - 25.07.2013, 16:33
Re: Bcrypt - by Edvin - 25.07.2013, 17:54
Re: Bcrypt - by Maxips2 - 25.07.2013, 19:30
AW: Bcrypt - by BigETI - 25.07.2013, 20:37
Re: AW: Bcrypt - by Johnson_boy - 25.07.2013, 21:59
Re: Bcrypt - by Red_Dragon. - 26.07.2013, 03:09
Re: Bcrypt - by Dan.. - 26.07.2013, 07:12
Re: Bcrypt - by Niko_boy - 26.07.2013, 07:20
Re: Bcrypt - by Johnson_boy - 26.07.2013, 17:23
Re: Bcrypt - by Dan.. - 26.07.2013, 18:27
AW: Re: Bcrypt - by BigETI - 26.07.2013, 23:32
Re: Bcrypt - by Lorenc_ - 27.07.2013, 01:43
Re: Bcrypt - by Dan.. - 27.07.2013, 07:51
Re: Bcrypt - by Johnson_boy - 28.07.2013, 12:10
Re: Bcrypt - by Johnson_boy - 06.08.2013, 23:45
Respuesta: Bcrypt - by GutierrezDeVelasco - 25.01.2014, 21:40
Respuesta: Bcrypt - by GutierrezDeVelasco - 25.01.2014, 21:49
Re: Bcrypt - by Kaperstone - 20.07.2014, 22:10
Re: Bcrypt - by Johnson_boy - 21.07.2014, 08:11
Re: Bcrypt - by maddinat0r - 21.07.2014, 20:07
Re: Bcrypt - by Sonical - 28.07.2014, 20:44
Re: Bcrypt - by Kaperstone - 28.08.2014, 23:30
Re: Bcrypt - by Kaperstone - 18.11.2014, 02:50
Re: Bcrypt - by Johnson_boy - 20.11.2014, 22:03
Re: Bcrypt - by Kaperstone - 21.11.2014, 04:49
Re : Bcrypt - by Maxime_Creteur - 25.11.2014, 18:21
Re : Bcrypt - by Nealll - 28.11.2014, 18:48
Re: Re : Bcrypt - by Johnson_boy - 28.11.2014, 20:35
Re : Bcrypt - by Nealll - 29.11.2014, 06:40
Re: Bcrypt - by Kaperstone - 01.12.2014, 13:33
Re : Bcrypt - by Nealll - 01.12.2014, 15:49
Re: Bcrypt - by Johnson_boy - 01.12.2014, 23:49
Re: Bcrypt - by ProKillerpa - 01.12.2014, 23:51
Re : Bcrypt - by Nealll - 02.12.2014, 18:20

Forum Jump:


Users browsing this thread: 3 Guest(s)