Advertisement
Guest User

Untitled

a guest
Oct 13th, 2016
86
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. userSchema.pre('save', function(next) {
  2. const user = this;
  3. // only rehash the password if the user alters the password!!!!!
  4. if (user.isModified('password')) {
  5.  
  6. bcrypt.genSalt(10, function(err, salt) {
  7.  
  8. if (err) { return next(err); }
  9.  
  10. bcrypt.hash(user.password, salt, null, function(err, hash) {
  11.  
  12. if (err) { return next(err); }
  13. user.password = hash;
  14. next();
  15.  
  16. });
  17. });
  18. } else {
  19. next();
  20. }
  21. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement