Verify Passwords with BCrypt.net

MaartenMM 1 Reputation point
2022-04-28T14:17:08.09+00:00

Hi all,

I'm having difficulties using the BCrypt-Offical NuGet package.

On my registration form the code I have to hash passwords is:

        string Emailadres = txtEmail.Text;

        string hashedPassword = BCrypt.Net.BCrypt.HashPassword(txtPaswoord.Text);
        

This code works fine and I can see that the passwords have been hashed in the database.

Code for login:

        GipLogin_Business.Business.Controller cont = new GipLogin_Business.Business.Controller();
        Session["Username"] = txtUsername.Text.Trim();
        string test = cont.Paswoordinvoer(Session["Username"].ToString());
        bool validPassword = BCrypt.Net.BCrypt.Verify(txtPassword.Text, test);
        int count = cont.deLogin(txtUsername.Text, txtPassword.Text);


        if (count == 1 && validPassword == false)
        {
            Session["Username"] = txtUsername.Text.Trim();
            Response.Redirect("Dashboard.aspx");
        }
        else lblErrorMessage.Visible = true;

Validreason always return "false"

Any help would be great, thanks!

Maarten

Developer technologies | ASP.NET | ASP.NET Core
Developer technologies | C#
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.