gpt4 book ai didi

node.js - bcrypt 在生成盐或散列密码时使应用程序崩溃

转载 作者:太空宇宙 更新时间:2023-11-03 23:17:44 25 4
gpt4 key购买 nike

根据 bcrypt npm 文档,我尝试合并该包,但无法在我的应用程序中使用 bcrypt 包,因此为了单独测试 bcrypt,我创建了示例 js 文件,该文件在执行时也会崩溃,而不会给出任何错误。下面是我尝试测试的js文件。我尝试将常量值传递给哈希函数,但这也不起作用。

const bcrypt = require('bcrypt');
async function run(){
const saltValue =await bcrypt.genSalt(10);
bcrypt.hash('12345',saltValue)
.then(result => console.log(result))
.catch(error => console.log(error));
}
run();

版本: Node :9.0.0npm: '5.5.1'“bcrypt”:“^3.0.2”,

使用nodemon,我收到消息:应用程序崩溃 - 启动前等待文件更改...在正常执行中,它没有显示任何错误。

更新:

如果将 bcrypt 的异步方法更改为同步,那么它工作正常,

    const saltValue = bcrypt.genSaltSync(10);
const hashed = bcrypt.hashSync('12345',saltValue);

我认为bcrypt团队的人可以回答。

更新:这个问题在社区中提出,很少有其他开发者面临同样的问题,有关更多信息,您可以引用链接。

https://github.com/kelektiv/node.bcrypt.js/issues/674

最佳答案

bcrypt 有时可能很时髦...替换为 bcryptjs (无论如何更受欢迎......)

这工作得很好:

const bcrypt = require('bcryptjs');

async function run() {
const saltValue = await bcrypt.genSalt(10);
bcrypt
.hash('12345', saltValue)
.then(result => console.log(result))
.catch(error => console.log(error));
}
run();

关于node.js - bcrypt 在生成盐或散列密码时使应用程序崩溃,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53254805/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com