Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- UserSchema.pre('save', function(next) {
- let user = this;
- if(!user.isModified('password')) return next(); //password has not modified
- bcrypt.genSalt(10, function (err, salt) {
- bcrypt.hash(user.password, salt, function (err, hash) {
- if(err) return next(err);
- user.password = hash;
- next();
- });
- });
- });
- UserSchema.methods.comparPassword = function(candidatePassword, cb) {
- bcrypt.compare(candidatePassword, this.password, function(err, isMatch) {
- if(err) return cb(err);
- cb(null, isMatch);
Add Comment
Please, Sign In to add comment