Password Reset In NodeJS

前端 未结 4 926
春和景丽
春和景丽 2021-01-31 11:15

I have made a set up to update a user\'s password using NodeJS/Passport. I followed this great guide: http://sahatyalkabov.com/how-to-implement-password-reset-in-nodejs/.

4条回答
  •  余生分开走
    2021-01-31 11:40

    I think the issue could be in the hash function. Tried duplicating you code into a simpler but similar experiment on my computer.

    As the bcrypt docs state here https://www.npmjs.com/package/bcrypt#to-hash-a-password

    The hash function only takes in 3 arguments, you send in 4. Whereas the third argument in your case is null.

    Here is some code to illustrate the issue and the, hopefully, solution

    Inside the salting callback

    bcrypt.hash(user.password, salt, null, function(err, hash) {
      if (err) return next(err);
      user.password = hash;
      next();
    });
    

    But change the third argument to be the callback function instead.

    bcrypt.hash(user.password, salt, function(err, hash) {
      if (err) return next(err);
      user.password = hash;
      next();
    });
    

提交回复
热议问题