繁体   English   中英

bcrypt.compare() 总是返回 false

[英]bcrypt.compare ( ) always returning false

我已经尝试将bcrypt (5.0.0 版)和bcryptjs (2.4.3 版)都尝试到 hash 并比较密码。 但是两个包中的比较 function 总是返回false

散列

userSchema.pre('save', async function (next) {
  this.password = await bcrypt.hash(this.password, 12);
  this.passwordConfirm = undefined;
  next();
});

比较

userSchema.methods.checkPassword = async function (inputPass, hashedPass) {
  return await bcrypt.compare(inputPass, hashedPass);
};

你不能使用 await function 和 return,试试

userSchema.methods.checkPassword = async function (inputPass, hashedPass) {
  let isValid = await bcrypt.compare(inputPass, hashedPass);
  return isValid;
};

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM