mongoose plugins:hash password fields
This plugin let you add a
hashed field to your schema. It automatically creates an async setter method for you,
as well as a setter virtual property.
Whenever you assign a value to the hashed field, it'll be hashed using bcrypt.
Plugin is intended to simplify the process of saving hashed passwords in the database.
Take this schema as example:
var mongoose = ;var hashedField = ;var UserSchema =name: String;UserSchema;var User = mongoose;var me = name: 'John';// Save the hashed value of secret in a new field named password_hashed// password is not saved in DB, only password_hashedmepassword = 'secret';
Later you can authenticate a password using an auto generated authenticate method:
You can pass the following options to Schema#plugin when creating the hashedField plugin:
field: a virtual setter name (defaults to password)
authMethod: the name for the authentication method (defaults to authenticate)
hashed_name: the real name of the hashed field in the DB (defaults to field_hash)
salt: salt value to pass on to bcrypt (defaults to 8)
setter: [optional] async setter function name