@slynova/hash

Flexible and Fluent framework-agnostic driver based system for password hashing algorithms.

Usage no npm install needed!

<script type="module">
  import slynovaHash from 'https://cdn.skypack.dev/@slynova/hash';
</script>

README

Hash

Download Version License

hash is a framework-agnostic package which provides a powerful wrapper for password hashing algorithms in Node.js.

There are currently 2 drivers available:

  • Argon2
  • Bcrypt

Getting Started

This package is available in the npm registry. It can easily be installed with npm or yarn.

$ npm i @slynova/hash
# or
$ yarn add @slynova/hash

When you require the package in your file, it will give you access to the HashManager class. This class is a facade for the package and should be instantiated with a configuration object.

const { HashManager } = require('@slynova/HashManager')
const hash = new HashManager(config)

Once you instantiated the manager, you can use the HashManager#use() method to retrieve a driver an use it.

hash.use() // Returns the default driver (specified in the config)
hash.use('argon2') // Returns the argon2 driver
hash.use('bcrypt', customConfig) // Overwrite the default configuration of the driver

Driver's API

Each driver implements the Interface Hash.

Methods

make(value: string, config?: Argon2Config | BcryptConfig): Promise<string>

This method will hash a plain value using the provided driver.

await hash.use('bcrypt').make('foo')
// $2b$10$RFgHztUoooIJEhuR4/e3ue4lZg36HYcIY2D7ptjB494FI/ctohaa6
verify(value: string, hash: string): Promise<boolean>

This method will verify an existing hash with the plain value using the provided driver.

await hash.use('bcrypt').verify('$2b$10$RFgHztUoooIJEhuR4/e3ue4lZg36HYcIY2D7ptjB494FI/ctohaa6', 'foo')

Contribution Guidelines

Any pull requests or discussions are welcome. Note that every pull request providing new feature or correcting a bug should be created with appropriate unit tests.