[英]bcrypt is crashing the app while generating salt or hashed password
根據 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();
版本:節點:9.0.0 npm:'5.5.1'“bcrypt”:“^3.0.2”,
使用 nodemon,我收到消息:應用程序崩潰 - 在開始之前等待文件更改...在正常執行中它沒有顯示任何錯誤。
更新:
如果使用同步更改 bcrypt 的異步方法,則它工作正常,
const saltValue = bcrypt.genSaltSync(10);
const hashed = bcrypt.hashSync('12345',saltValue);
我認為 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();
我有節點 v8.11.4 和 bcrypt 4.0.1 版本。
我有同樣的錯誤
[nodemon] 應用程序崩潰 - 在啟動之前等待文件更改..
我的解決方案:
我確實安裝了 bcrypt 舊版本。
npm i --save --save-exact bcrypt@2.0.1
它工作正常
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.