const saltRounds = bcrypt.genSaltSync(10);
var hashedPassword = bcrypt.hashSync(ctx.params.password, saltRounds);
var validPassword = bcrypt.compareSync(hashedPassword, result.password);
result.password
是密码,保存在数据库中
答案 0 :(得分:0)
根据documentation,您应该将纯文本密码作为第一个参数传递给bcrypt.compareSync()
:
const saltRounds = bcrypt.genSaltSync(10);
const plainTextPassword = ctx.params.password;
const hashedPassword = bcrypt.hashSync(plainTextPassword, saltRounds);
const valid = bcrypt.compareSync(plainTextPassword, hashedPassword);