hashed password setter to mongoose schema
JavaScript
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Failed to load latest commit information.
lib
README.md
index.js
package.json

README.md

mongoose-hashed-password

hashed password setter to mongoose schema

Installation

$ npm install mongoose-hashed-password

Example

require('mongoose-hashed-password');  // This module
var mongoose = require('mongoose');
var db = mongoose.connect('mongodb://localhost/test');

var schema = new mongoose.Schema({ user_id: String });
var User = db.model('User', schema);

User.defineHashedPassword('sha256');  // Define hashed password

var user = new User({ user_id: 'hoge', password: 'huga' });  // Set 'password'
console.log(user);  // { user_id: 'hoge', hashed_password: '...', salt: '...' }
console.log(user.password);  // 'huga'
user.save(function (err) {
    // ...
})

Add Validation

User.defineHashedPassword('sha256', validatePassword);

function validatePassword(value) {
    return value && value.length >= 4;  // The password must be at least 4 characters long
}