【问题标题】:UnhandledPromiseRejectionWarning: Error: data and salt arguments requiredUnhandledPromiseRejectionWarning:错误:需要数据和盐参数
【发布时间】:2021-07-08 11:33:19
【问题描述】:

这段代码有这个错误:

async function get(user) {
  user = await Joi.validate(user, userSchemaGet, { abortEarly: false });
  await User.findOne(
    {_id: user._id}, 
    (err, res) => {
      if(err){
        console.log("ERROR : ")
        console.log(err)
      } else {
        console.log("res")
        console.log(res);
        if(bcrypt.hash(user.password, 10) === res.hashedPassword) {
          return res;
        }
      }
    });
}

我阅读了有关此主题的所有 stackoverflow,但没有任何反应。 ps : 昨天运行的很完美...

【问题讨论】:

    标签: node.js bcrypt


    【解决方案1】:

    1) user.password 可能为 null 或未定义。在将 user 值传递给 hash 函数之前检查它。

    2) bcrypt.hash 是一个承诺,但您将其用作正常功能。

    3) bcrypt 有一个特殊的比较函数,用于检查密码是否与哈希匹配。你应该在这里使用它。

    Bcrypt docs

    【讨论】:

      猜你喜欢
      • 2020-10-28
      • 1970-01-01
      • 2018-06-23
      • 1970-01-01
      • 1970-01-01
      • 2020-12-13
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多