This plugin automatically adds automatic password hashing to your Objection.js models. This makes it super-easy to secure passwords and other sensitive data.
Under the hood, the plugin uses bcrypt for hashing.
Installation
NPM
npm i objection-password-bcrypt-nodejs
Yarn
yarn add objection-password-bcrypt-nodejs
Usage
Hashing your data
// import the pluginconst Password = ;const Model = Model; // mixin the pluginModel static { return 'person'; } const person = await Person; console;// $2a$12$sWSdI13BJ5ipPca/f8KTF.k4eFKsUtobfWdTBoQdj9g9I8JfLmZty
Verifying the data
// the password to verifyconst password = 'q1w2e3r4'; // fetch the person by emailconst person = await Person; // verify the password is correctconst passwordValid = await person;
Options
There are a few options you can pass to customize the way the plugin works.
These options can be added when instantiating the plugin. For example:
// import the pluginconst Password = passwordField: 'hash';
allowEmptyPassword
(defaults to false
)
Allows an empty password to be set.
passwordField
(defaults to password
)
Allows you to override the name of the field to be hashed.
rounds
(defaults to 12
)
The number of number of bcrypt rounds to use when hashing the data.