SHARE
TWEET

Untitled

a guest Dec 13th, 2016 64 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. // JS, Mongoose, Mongo, ExpressJS, Authentication, Security. Bcrypt
  2.  
  3. // Before saving user object
  4. userSchema.pre('save', function(next) {
  5.   const user = this;
  6.  
  7.   //Generate a salt then run callback 10: number of rounds
  8.   bcrypt.genSalt(10, function(err, salt){
  9.     if (err) {return next(err)}
  10.    
  11.     //Hash the pass using salt
  12.     bcrypt.hash(user.password, salt, null, function(err, hash){
  13.       if (err) {return next(err)}
  14.      
  15.       user.password = hash;
  16.       next();
  17.     });
  18.   });
  19. });
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
 
Top