Advertisement
Guest User

Untitled

a guest
Feb 17th, 2017
161
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.73 KB | None | 0 0
  1. var mongoose=require('mongoose');
  2. var bycrypt=require('bcrypt-nodejs');
  3. var schema=mongoose.Schema;
  4. var userSchema=new schema({
  5. username :{type:String,lowercase:true,required:true,unique:true},
  6. password :{type:String,lowercase:true,required:true},
  7. email:{type:String,lowercase:true,required:true,unique:true}
  8. });
  9.  
  10. userSchema.pre('save',function(next){
  11. var user=this;
  12. bycrypt.hash(user.password, null, null, function(err, hash) {
  13. if(err) next(err);
  14. user.password=hash;
  15. next();
  16. });
  17. });
  18.  
  19. userSchema.methods.comparePassword=function(password){
  20.  
  21. console.log(bycrypt.compareSync(password, this.password));
  22.  
  23. return bycrypt.compareSync(password, this.password);
  24. };
  25. module.exports=mongoose.model("user",userSchema);
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement