kelektiv / node.bcrypt.js

bcrypt for NodeJs
MIT License
7.51k stars 518 forks source link

Node getting stuck on bcrypt.hash and bcrypt.hashSync. #661

Closed Aashir1 closed 6 years ago

Aashir1 commented 6 years ago

My Node getting stuck on bcrypt.hash and bcrypt.hashSync. However, if I comment these statement my code going well. I am being hangout in this error since morning. This is my code. userDocument.password = bcrypt.hashSync(userDocument.password, salt); bcrypt.hashSync(userDocument.password, salt, (err, hash) => { if (!err) { userDocument.password = hash; console.log('userDocument.password: ', userDocument.password) console.log("userDocument: ", userDocument); console.log('userDOcument: ', userDocument); userDocument.save((err, user) => { if (!err) { delete user.password; console.log('if from controller', user); return AuthController.sendResponse(res, user); } if (err.code == 11000) { let error = { code: err.code, message: err.message } return AuthController.throwError(res, error, 400); } }) } })

Aashir1 commented 6 years ago

i resolved this issue by replacing salt value 20 to 10.

recrsn commented 6 years ago

Rounds >13 will take a long time to complete. Refer to the table in the README for details. Any particular reason you need to use hashSync?

jorgevilasboas commented 5 years ago

I had the same problem, Now I use in a easier way:

const bcrypt = require("bcryptjs");

let hash = bcrypt.hashSync("myPassword", 10);
console.log(hash);

if (bcrypt.compareSync("myPassword", hash)) {
  // Passwords match
  console.log("Passwords match");
} else {
  // Passwords don't match
  console.log("Passwords don't match");
}
BudiSalah commented 4 years ago

Wrapping process.env.SALT solved this problem for me.