BCryptHelper.CheckPassword always returns false

巧了我就是萌 提交于 2019-12-02 03:19:27

Maybe the problem is not in the hashing itselft, maybe it's the way you store the password in the database and retrieve it afterwords or something like that.

First step I would take is to write a unit test to check the functionality of that class

[TestClass]
public class BCryptHasherTest
{
    [TestMethod]
    public void check_hashing_works_for_valid_password()
    {
        string password = "myDummyPassword!";
        string hashedPassword = BCryptHasher.EncryptPassword(password);

        var passwordsMatch = BCryptHasher.CheckPasswordMatch(password, hashedPassword);      
        Assert.IsTrue(passwordsMatch);
    }
}

If this passes, the problem is somewhere else in your code, so you can go ahead and test for other things until you have found the issue.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!