bcrypt.compare 承诺总是 return 错误

bcrypt.compare with Promise always return false

我是 Express.js 和 Passport.js 的新手,所以可能我做错了什么,因为 bcrypt comapre 函数总是 return false。

public static findUser = async ({ email, password }) => {
  const pool = await new sql.ConnectionPool(CommonConstants.connectionString).connect();
  const request = pool.request();
  const result = await request
    .input("Email", sql.NVarChar, email)
    .execute("FindUserSP");
  const user = result.recordset;
  return await bcrypt.compare(password, user[0].Password) ? user : {};
};

这就是哈希的创建方式:

const password = req.body.Password;
const email = req.body.Email;
const salt = await bcrypt.genSalt(10);
const hash = await bcrypt.hash(password, salt);

测试用例:

Hash: b$nK1.wW71NcBIQkMQq6wpHe/HMhCjOaQNy9BpfPDef01
password: 123
version: 3.0.2

检查数据库没有截断数据。散列通常应为 60 个字符,而不是 50 个字符:

const salt = await bcrypt.genSalt(10);
const hash = await bcrypt.hash(password, salt);

测试: https://repl.it/@CodyGeisler/bcrypt-test?language=nodejs