Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- // JS, Mongoose, Mongo, ExpressJS, Authentication, Security. Bcrypt
- // Before saving user object
- userSchema.pre('save', function(next) {
- const user = this;
- //Generate a salt then run callback 10: number of rounds
- bcrypt.genSalt(10, function(err, salt){
- if (err) {return next(err)}
- //Hash the pass using salt
- bcrypt.hash(user.password, salt, null, function(err, hash){
- if (err) {return next(err)}
- user.password = hash;
- next();
- });
- });
- });
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement