简体   繁体   中英

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. Below is the js file which I tried to test. 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",

With nodemon, I am getting message: app crashed - waiting for file changes before starting... in normal execution it is not showing any error.

Update:

If change the bcrypt's async methods with synchronous then it is working fine,

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

I think someone from bcrypt team can answer.

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

bcrypt can be funky sometimes... replace with bcryptjs (far more popular anyway...)

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.

I got same error

[nodemon] app crashed - waiting for file changes before starting.. .

My solution:

I did install bcrypt old version.

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

It works fine

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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