Advertisement
Guest User

Untitled

a guest
Feb 28th, 2016
81
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.42 KB | None | 0 0
  1. UserSchema.pre('save', function (next) {
  2. var user = this;
  3. if (this.isModified('password') || this.isNew) {
  4. bcrypt.genSalt(10, function (err, salt) {
  5. if (err) {
  6. return next(err);
  7. }
  8. bcrypt.hash(user.password, salt, function(err, hash) {
  9. if (err) {
  10. return next(err);
  11. }
  12. user.password = hash;
  13. next();
  14. });
  15. });
  16. } else {
  17. return next();
  18. }
  19. });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement