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

ASP.NET Core
ASP.NET Core
A set of technologies in the .NET Framework for building web applications and XML web services.
4,393 questions
C#
C#
An object-oriented and type-safe programming language that has its roots in the C family of languages and includes support for component-oriented programming.
10,638 questions
{count} votes