bcrypt Error: data and hash arguments required

后端 未结 4 940
忘了有多久
忘了有多久 2020-12-18 22:07

I am getting a bcrypt error stating that data and hash arguments are required, referencing line #44 in my routes.js file. From what I can tell, I am passing that information

相关标签:
4条回答
  • 2020-12-18 22:45

    bcrypt.compare takes 3 parameters; passwordToCheck, passwordHash, and a callback, respectively. (Check the documentation for examples)

    This error means one or both of the first 2 parameters are either null or undefined. Therefore, make sure both of them are passed correctly. (Not as null or undefined)

    0 讨论(0)
  • 2020-12-18 22:46
    const passwordMatch = await bcrypt.compare(password, user.password);
    

    Make sure you are giving raw password and hash password. This will return a boolean value.

    0 讨论(0)
  • 2020-12-18 22:46

    I had the same error and the problem was a missing await when calling the function that reads from database

    0 讨论(0)
  • 2020-12-18 22:53

    I used

    const user = await User.find({email: req.body.email}) //which returned all users
    

    //and unless i reference the first user in index 0, i can't pass user.password to the //bcrypt compare method because it's not a string I changed it to

    await User.findOne({email: req.body.email})//from which i can use user.password in the //bcrypt compare method
    
    0 讨论(0)
提交回复
热议问题