GithubHelp home page GithubHelp logo

maddinat0r / bcrypt-samp Goto Github PK

View Code? Open in Web Editor NEW

This project forked from lassir/bcrypt-samp

3.0 3.0 0.0 718 KB

Multithreaded bcrypt implementation for SA-MP

License: Other

C 72.14% C++ 27.86%

bcrypt-samp's Introduction

Bcrypt for SA-MP

An implementation of the bcrypt hashing algorithm for PAWN written in C++.

Benefits of bcrypt

  • 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

Functions

  • bcrypt_hash(key[], cost, callback_name[], callback_format[], {Float, _}:...);
  • bcrypt_get_hash(dest[]);
  • bcrypt_check(key[], hash[], callback_name[], callback_format[], {Float, _}:...);
  • bool:bcrypt_is_equal();

Usage

  • Copy the include and plugin file to their appropriate directories

  • Use bcrypt_hash if you want to hash user input (e.g. passwords, or when updating the work factor). Once the hash is calculated, the specified callback is called and the hash can be accessed with the function bcrypt_get_hash.

  • Use bcrypt_check if you want to verify whether or not user input matches a given hash (e.g. on login). Once the verification is done, the specified callback will be called. The function bcrypt_is_equal returns true or false whether or not the password matched the hash.

Example

#include <a_samp>
#include <bcrypt>


// Hashing a password
bcrypt_hash("MyPassword", 12, "OnPlayerRegister", "d", playerid);

forward public OnPlayerRegister(playerid);
public OnPlayerRegister(playerid)
{
	new hash[61]; //the hash length is always 60
	bcrypt_get_hash(hash);
	
	printf("Password hashed for playerid %d: %s (registration)", playerid, hash);
	// Could print for instance:
	//    "Password hashed for playerid 32: $2a$12$izP1Fy.pZxOjDOCVma0UneQoQ3sUX3HxfmyibOLPcafDSL8Pj.Ety (registration)"
	// The hash will be different every time even for the same input due to the random salt
    return 1;
}

// Checking a password
bcrypt_check(inputtext, hash, "OnPlayerLogin", "d", playerid);

forward public OnPlayerLogin(playerid);
public OnPlayerLogin(playerid)
{
	printf("Password checked for playerid %d: %s (login)", playerid, (bcrypt_is_equal()) ? ("Correct password") : ("Incorrect password"));

    return 1;
}

bcrypt-samp's People

Contributors

lassir avatar maddinat0r avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.