Advertisement
Guest User

Untitled

a guest
Dec 13th, 2016
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.48 KB | None | 0 0
  1. // JS, Mongoose, Mongo, ExpressJS, Authentication, Security. Bcrypt
  2.  
  3. // Before saving user object
  4. userSchema.pre('save', function(next) {
  5. const user = this;
  6.  
  7. //Generate a salt then run callback 10: number of rounds
  8. bcrypt.genSalt(10, function(err, salt){
  9. if (err) {return next(err)}
  10.  
  11. //Hash the pass using salt
  12. bcrypt.hash(user.password, salt, null, function(err, hash){
  13. if (err) {return next(err)}
  14.  
  15. user.password = hash;
  16. next();
  17. });
  18. });
  19. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement