iro*_*man 5 bcrypt node.js npm
根据 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();
Run Code Online (Sandbox Code Playgroud)
版本:节点:9.0.0 npm:'5.5.1'“bcrypt”:“^3.0.2”,
使用nodemon,我收到消息:应用程序崩溃 - 启动前等待文件更改...在正常执行中,它没有显示任何错误。
更新:
如果将 bcrypt 的异步方法更改为同步,那么它就可以正常工作,
const saltValue = bcrypt.genSaltSync(10);
const hashed = bcrypt.hashSync('12345',saltValue);
Run Code Online (Sandbox Code Playgroud)
我想bcrypt团队的人可以回答。
更新:这个问题在社区中提出,很少有其他开发者面临同样的问题,有关更多信息,您可以参考链接。
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();
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
3309 次 |
| 最近记录: |