Created
September 24, 2016 22:05
-
-
Save dsomel21/add4fc249891d3c332f8bd934fb78ac1 to your computer and use it in GitHub Desktop.
Mongo user model with validation and exncryption functions
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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