简体   繁体   English

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

[英]bcrypt is crashing the app while generating salt or hashed password

As per the bcrypt npm documentation I tried to incorporate the package but unable to use bcrypt package in my app, so to test the bcrypt separately I created sample js file which is also crashing on execution without giving any error.根据 bcrypt npm 文档,我尝试合并该包,但无法在我的应用程序中使用 bcrypt 包,因此为了单独测试 bcrypt,我创建了示例 js 文件,该文件在执行时也会崩溃而没有给出任何错误。 Below is the js file which I tried to test.下面是我试图测试的 js 文件。 I tried to pass the constant value to hash function, which is also not working.我试图将常量值传递给哈希函数,这也不起作用。

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();

Version: node : 9.0.0 npm: '5.5.1' "bcrypt": "^3.0.2",版本:节点:9.0.0 npm:'5.5.1'“bcrypt”:“^3.0.2”,

With nodemon, I am getting message: app crashed - waiting for file changes before starting... in normal execution it is not showing any error.使用 nodemon,我收到消息:应用程序崩溃 - 在开始之前等待文件更改...在正常执行中它没有显示任何错误。

Update:更新:

If change the bcrypt's async methods with synchronous then it is working fine,如果使用同步更改 bcrypt 的异步方法,则它工作正常,

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

I think someone from bcrypt team can answer.我认为 bcrypt 团队的某个人可以回答。

Update : This issue raised on the community and few other developers are facing the same issue, for more information you can refer the link.更新:这个问题在社区中提出,很少有其他开发人员面临同样的问题,有关更多信息,您可以参考链接。

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

bcrypt can be funky sometimes... replace with bcryptjs (far more popular anyway...) bcrypt 有时可能很时髦……用bcryptjs替换(反正更流行……)

This works just fine:这工作得很好:

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();

I have node v8.11.4 and bcrypt 4.0.1 version.我有节点 v8.11.4 和 bcrypt 4.0.1 版本。

I got same error我有同样的错误

[nodemon] app crashed - waiting for file changes before starting.. . [nodemon] 应用程序崩溃 - 在启动之前等待文件更改..

My solution:我的解决方案:

I did install bcrypt old version.我确实安装了 bcrypt 旧版本。

npm i --save --save-exact bcrypt@2.0.1

It works fine它工作正常

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM