modella-bcrypt
v1.0.2
Published
Adds a hashed field to a model using bcrypt-nodejs and a method to verify it. Can be used for password encryption.
Downloads
4
Maintainers
Readme
modella-bcrypt
Adds a hashed field to a model using bcrypt-nodejs and a method to verify it. Can be used for password encryption.
Installation
npm install modella-bcrypt
Usage
Encrypt field password
.
var modella = require('modella');
var encrypter = require('modella-bcrypt');
var User = modella('User');
User.use(encrypter({ fieldName: 'password' }));
User.
attr('_id').
attr('email').
attr('password');
var user = new User({
email: '[email protected]',
password: 'secret'
});
user.save(function () {
// user.password === [Hashed password]
});
To verify the password of the user:
user.compareField('password', pass, function (err, match) {
// match === true if verification is correct
});
// or
user.compareFieldSync(pass); // true or false
Options
fieldName
Sets the name of the field to use, defaults to password
.
User.use(encrypter({ fieldName: 'pass' });
rounds
Sets the bcrypt rounds. Rounds determine the complexity used for encryption with bcrypt-nodejs (see bcrypt-nodejs docs).
User.use(encrypter({ rounds: 8 });