Advertisement
Guest User

Untitled

a guest
Oct 31st, 2017
76
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.49 KB | None | 0 0
  1. userSchema.pre('save', function userPreSave(next) {
  2. const user = this;
  3. if (this.isModified('password') || this.isNew) {
  4. return bcrypt.hash(user.password, 10)
  5. .then((hash) => {
  6. user.password = hash;
  7. return next();
  8. })
  9. .catch(err => next(err));
  10. }
  11. return next();
  12. });
  13.  
  14. userSchema.methods.comparePassword = function userComparePassword(password) {
  15. return bcrypt.compare(password, this.password);
  16. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement