bcrypt.hash 不调用其回调



由于某种原因,bcrypt.hash方法挂起并且从不调用其回调。

bcrypt.genSalt(29, function(err, salt) {
if (err) {
res.json({ success: false, msg: err.message });
} else {
bcrypt.hash(req.body.password, salt, function (err, hash) {
// This function is never called
res.json({ success: true });
});
}
});

有什么建议吗?

更新

它似乎与快递无关.js等等。 我刚刚创建了一个脚本文件test.js

var bcrypt = require('bcrypt');
var pwd = 'Test password 123';
bcrypt.genSalt(29, function(err, salt) {
if (err) {
console.log('1: ' + err.message);
} else {
console.log('Salt: ' + salt);
bcrypt.hash(pwd, salt, function (err, hash) {
if (err) {
console.log('2: ' + err.message);
} else {
console.log('Hash: ' + hash);
}
});
}
});

然后我通过使用node test.js开始它。它输出一个盐,然后挂断,bcrypt.hash在任何情况下都不会调用其回调函数,无论是否出错。我正在OS X上工作,并且安装了节点v7.8.0。

29 个盐回合意味着Math.pow(2, 29)个关键扩展回合,这将需要很长时间。

举例说明:

  • 10 发子弹在我的 MBP 上大约需要 78 毫秒
  • 12发大约需要300ms
  • 14发大约需要1170ms
  • 16发大约需要4700ms

您也许可以计算出使用 29 轮需要多长时间(大约 260 万秒,或大约一个月)。

最新更新