【问题标题】:bcrypt.gentSalt is not a function is not definedbcrypt.gentSalt 不是一个未定义的函数
【发布时间】:2021-07-19 18:08:46
【问题描述】:

我在散列密码时卡住了。这是我的代码:

const salt = await bcrypt.gentSalt(10);
const hashPassword = await bcrypt.hash(req.body.password, salt);

这是我的用户身体数据代码:

const user = new User({
  name: req.body.name,
  email: req.body.email,
  password: hashPassword,
});

【问题讨论】:

  • "gentSalt" !== "genSalt".

标签: javascript node.js web hash


【解决方案1】:

https://www.npmjs.com/package/bcrypt查看“用法”下的示例:

bcrypt.genSalt(saltRounds, function(err, salt) {
  bcrypt.hash(myPlaintextPassword, salt, function(err, hash) {
    // Store hash in your password DB.
  });
});

它告诉你它不存在,因为你有一个错字。您应该使用.genSalt() 而不是.gentSalt()

【讨论】:

    猜你喜欢
    • 2015-03-16
    • 2015-03-02
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2018-01-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多