加密密码节点JS

问题描述 投票:2回答:1

我得到告诉的错误

UnhandledPromiseRejectionWarning:错误:非法参数:string,未定义

const bcrypt = require('bcryptjs');
    myFunction = async () =>{
        const password = 'Red1234';
        const hashedPassword = await bcrypt.hash(password);

        console.log(hashedPassword);

        const isMatch = await bcrypt.compare('Red1234',hashedPassword);
        console.log(isMatch);
    }
    myFunction();
node.js bcrypt
1个回答
0
投票

由于出现此错误,因为您没有指定旋转数(盐)来生成所提供密码的哈希值。请查看以下代码。

const bcrypt = require('bcryptjs');
    myFunction = async () =>{
        const password = 'Red1234';
        const hashedPassword = await bcrypt.hash(password, NumberOfRotations);

        // e.g const hashedPassword = await bcrypt.hash(password,8);

        console.log(hashedPassword);

        const isMatch = await bcrypt.compare('Red1234',hashedPassword);
        console.log(isMatch);
    }
    myFunction();

© www.soinside.com 2019 - 2024. All rights reserved.