Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- var mongoose=require('mongoose');
- var bycrypt=require('bcrypt-nodejs');
- var schema=mongoose.Schema;
- var userSchema=new schema({
- username :{type:String,lowercase:true,required:true,unique:true},
- password :{type:String,lowercase:true,required:true},
- email:{type:String,lowercase:true,required:true,unique:true}
- });
- userSchema.pre('save',function(next){
- var user=this;
- bycrypt.hash(user.password, null, null, function(err, hash) {
- if(err) next(err);
- user.password=hash;
- next();
- });
- });
- userSchema.methods.comparePassword=function(password){
- console.log(bycrypt.compareSync(password, this.password));
- return bycrypt.compareSync(password, this.password);
- };
- module.exports=mongoose.model("user",userSchema);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement