带Promise的bcrypt.compare总是返回false

时间:2018-12-03 17:24:18

标签: node.js express passport.js bcrypt

我是Express.js和Passport.js的新手,所以我可能做错了,因为bcrypt comapre函数始终返回false。

@RunWith(AndroidJUnit4.class)
 public class MainScreenTest {

@Rule
public ActivityTestRule<MainActivity> mainActivityActivityTestRule =
        new ActivityTestRule<>(MainActivity.class);

@Test
public void floatingActionButton() {
    onView(withId(R.id.floating_action_button))
            .check(matches(isDisplayed()));
}

这就是创建哈希的方式:

function getHelp (with) : SomeSignatureHere {      
   return function () {
     return 'Help with '+with;
   }
}

测试用例:

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 : {};
};

1 个答案:

答案 0 :(得分:0)

检查数据库未截断数据。哈希通常应为60个字符,而不是以下来源的50个字符:

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

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