Skip to content

Instantly share code, notes, and snippets.

@dsomel21
Created September 24, 2016 22:05
Show Gist options
  • Save dsomel21/add4fc249891d3c332f8bd934fb78ac1 to your computer and use it in GitHub Desktop.
Save dsomel21/add4fc249891d3c332f8bd934fb78ac1 to your computer and use it in GitHub Desktop.
Mongo user model with validation and exncryption functions
var mongoose = require('mongoose');
var bcrypt = require('bcrypt-nodejs');
var user = mongoose.Schema({
local: {
firstname: String,
lastname: String,
email: String,
password: String
},
});
user.methods.generateHash = function(password) {
return bcrypt.hashSync(password, bcrypt.genSaltSync(8), null);
};
user.methods.validPassword = function(password) {
return bcrypt.compareSync(password, this.local.password);
};
module.exports = mongoose.model('User' , user);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment