Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- UserSchema.pre('save', function (next) {
- var user = this;
- if (this.isModified('password') || this.isNew) {
- bcrypt.genSalt(10, function (err, salt) {
- if (err) {
- return next(err);
- }
- bcrypt.hash(user.password, salt, null, function (err, hash) {
- if (err) {
- return next(err);
- }
- user.password = hash;
- next();
- });
- });
- } else {
- return next();
- }
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement