Skip to content

GDGVIT/bcrypt-rust-wasm

Repository files navigation

bcrypt-wasm-rust

Optimized bcrypt implementation in WASM, written in rust.

npm version


Functionalities

  • Hash passwords
  • Custom rounds for salt
  • Verify hashed passwords
  • Faster than the pure JS implementation

Instructions to run

  • Pre-requisites:
    • NPM

Installation with NPM

npm i -s bcrypt-rust-wasm

Usage

This library is currently compatible with NodeJS and supports the synchronous bindings only.

Importing

const { Bcrypt } = require('bcrypt-rust-wasm');
...

Obtaining an instance

// Get a bcrypt instance with a default number of seed rounds
const bcryptDefault = Bcrypt.default();

// Get a bcrypt instance with a specified number of seed rounds
const bcrypt = Bcrypt.new(10);

Hashing

const hash = bcrypt.hashSync('password'); 
// hash: "$2b$04$fsiGFAMtgNJ8YIszhoxusObEgoLF.faqMIKXiRDp5GZbzFWzebgcu"

Verifying a hash

bcrypt.verifySync("password", hash) // true
bcrypt.verifySync("password123", hash) // false

Building from source

How to build in release mode

# Builds the project and places it into the `pkg` folder.
npm run build

Dependencies for building

Contributors

  • @ATechnoHazard - for the implementation
  • @L04DB4L4NC3R - for the idea


Made with ❤️ by DSC VIT