Giter VIP home page Giter VIP logo

bcrypt's Introduction

BCrypt

Platforms

A library to help you hash passwords. You can read about bcrypt in Wikipedia as well as in the following article: How To Safely Store A Password

bcrypt

Installation

Via Boss

For ease I recommend using the Boss (Dependency Manager for Delphi) for installation, simply by running the command below on a terminal (Windows PowerShell for example):

boss install https://github.com/viniciussanchez/bcrypt

Manual

If you choose to install manually, simply add the following folders to your project, in Project > Options > Resource Compiler > Directories and Conditionals > Include file search path

../bcrypt/src

Usage

Generate hash

var
  LHash: string;
begin
  LHash := TBCrypt.GenerateHash(password, cost, type);
end;

Where

  • password is the password to be hashed
  • type is one of THashType.PHP, THashType.BSD, or THashType.Default, THashType.BSD is the default $2a$
  • cost is a number between 10 and 30, default is 10

Compare hash

var
  LVerify : Boolean;
begin
  LVerify := TBCrypt.CompareHash(password, hash);
end;

Where

  • password is the password to be verified
  • hash is a hash generated, similar to $2y$12$GuC.Gk2YDsp8Yvga.IuSNOWM0fxEIsAEaWC1hqEI14Wa.7Ps3iYFq

Get hash info

var
  LHashInfo: THashInfo;
  LSalt, LHash: string;
  LHashType: THashType;
  LCost: Word;
begin
  LHashInfo := TBCrypt.GetHashInfo(hash);
  LCost := LHashInfo.Cost;
  LSalt := LHashInfo.Salt;
  LHash := LHashInfo.Hash;
  LHashType := LHashInfo.&Type;

Where

  • hash is a hash generated

Needs rehash

var
  LNeeds : Boolean;
begin
  LNeeds := TBCrypt.NeedsRehash(hash, cost);
end;

Where

  • hash is a hash, similar to $2y$12$GuC.Gk2YDsp8Yvga.IuSNOWM0fxEIsAEaWC1hqEI14Wa.7Ps3iYFq
  • cost is a number between 10 and 30, default is 10

Hash Info

The characters that comprise the resultant hash are:

./ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789

Resultant hashes will be 60 characters long.

bcrypt-calculation-time

Credits

The code for this comes from a few sources:

bcrypt's People

Contributors

viniciussanchez avatar josiasmaceda 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.