@cwasm/openbsd-bcrypt
TypeScript icon, indicating that this package has built-in type declarations

0.1.0 • Public • Published

OpenBSD BCrypt

BCrypt hashing for Node.js, using OpenBSD BCrypt compiled to WebAssembly.

Entropy when generating salts are provided by crypto.randomFillSync from Node.js.

Timing attacks are mitigated by using the constant time comparison function crypto.timingSafeEqual from Node.js.

Installation

npm install --save @cwasm/openbsd-bcrypt

Usage

const bcrypt = require('@cwasm/openbsd-bcrypt')


// When user signs up
const hash = bcrypt.hashSync('password', 12)


// When user logs in
if (bcrypt.compareSync('password', hash)) {
  // The password was correct
}

API

compareSync(password, hash)

  • password (string, required) - The password to be checked.
  • hash (string, required) - The hash to be checked against.
  • returns boolean - True if the password matches the hash, false otherwise.

Test a password against a previously computed hash.

genSaltSync(rounds)

  • rounds (number, required) - The number of rounds to use when generating the salt.
  • returns string

Generate a salt.

hashSync(password, rounds)

  • password (string, required) - The password to hash.
  • rounds (number, required) - The number of rounds to use when generating the salt.
  • returns string

Generate a hash for the given password, using a random salt.

Package Sidebar

Install

npm i @cwasm/openbsd-bcrypt

Weekly Downloads

1

Version

0.1.0

License

MIT

Unpacked Size

45 kB

Total Files

5

Last publish

Collaborators

  • linusu