我得到告诉的错误
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();
由于出现此错误,因为您没有指定旋转数(盐)来生成所提供密码的哈希值。请查看以下代码。
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();