Tuesday 9 May 2017

Why my bcrypt not hash password

I tried this code to hash pass word , but it not work ,nothing error , just not hash password . Can anyone show me where my wrong ? Here is the code

userSchema.pre('save',(next) =>{
    var user = this;
    if(!user.isModified('password')) {
    return next();
  }
    bcrypt.genSalt(10,(err,salt) =>{
        if(err) {return next(err)};
        bcrypt.hash(user.password,salt,null,(err,hash) =>{
            if(err) {return next(err)};
                user.password = hash;
            next();
    });

    });

});



via Thanh Tùng

No comments:

Post a Comment