Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6886207
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 27, 20262026-05-27T05:43:50+00:00 2026-05-27T05:43:50+00:00

I am using .net connector for mysql. I went to code a user login

  • 0

I am using .net connector for mysql. I went to code a user login form, that seems to work correctly, but when i click the login button with valid login details, it tells me i logged in successfully then tells me its a wrong user/pass combo.

here is the code and everything seems the way it should be.

The program checks the hashed password against the one entered in the database, which all works nicely. But for some reason the “successfully logged in” messagebox shows then right after, the “wrong username/password combo” messagebox shows.

I’ve been trying to figure out where i went wrong for the past 2 days and its drivin me nuts. maybe you guys can see where i screwed up lol

the code:

            try
        {
            MySqlConnection connection = new MySqlConnection(MyConString);
            MySqlCommand command = connection.CreateCommand();
            MySqlDataReader Reader;
            command.CommandText = "select * from users";
            try
            {
                connection.Open();
            }
            catch (Exception ex)
            {
                listBox4.Items.Add(ex);
                MessageBox.Show("There has been an error connecting to the user database! Please try again later.");
            }
            Reader = command.ExecuteReader();
            while (Reader.Read())
            {
                if (textBox4.Text == Reader.GetString(2))
                {
                    string haspass= CryptorEngine.Encrypt(textBox5.Text, true);
                    if (haspass == Reader.GetString(3))
                    {
                            MessageBox.Show("Successfully logged in!");
                    }
                    else
                    {
                        MessageBox.Show("Wrong Unhashed Username/Password Combination");
                    }
                }
                else
                {
                    MessageBox.Show("Wrong Username/Password Combination");
                }
            }
            connection.Close();
        }
        catch (Exception ex)
        {
            listBox4.Items.Add(ex);
        }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-27T05:43:51+00:00Added an answer on May 27, 2026 at 5:43 am

    Here’s a better way to do it:

    try
    {
        MySqlConnection connection = new MySqlConnection(MyConString);
        MySqlCommand command = connection.CreateCommand();
        MySqlDataReader Reader;
        //Change the "username" and "password" to the corresponding names of these columns in your table
        command.CommandText = "SELECT * FROM users WHERE username = @username AND password = @password LIMIT 1";
        //assuming textbox4 has the username
        command.Parameters.AddWithValue("@username", textBox4.Text); 
        command.Parameters.AddWithValue("@password", CryptorEngine.Encrypt(textBox5.Text, true));
    
        try
        {
            connection.Open();
        }
        catch (Exception ex)
        {
            listBox4.Items.Add(ex);
            MessageBox.Show("There has been an error connecting to the user database! Please try again later.");
            //you should return here since if there's no connection you can't run the query
        }
    
        Reader = command.ExecuteReader();
    
        if(Reader.HasRows){
            MessageBox.Show("Successfully logged in!");
        }
        else
        {
            MessageBox.Show("Wrong Username/Password Combination");
        }
    
        connection.Close();
    }
    catch (Exception ex)
    {
        listBox4.Items.Add(ex);
    }
    

    This will only return one row (if it exists).

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am using MySQL .net connector 6.4.4.0 and Entity Frame work 4.1 and trying
I'm using VS2010 with the MySQL .NET Connector . My project that used to
I'm using MySql Connector .NET to load an account and transfer it to the
How to create a database using connector/net programming? How come the following doesn't work?
I'm using .NET Connector to connect to MySQL. In my application there are few
I'm a beginner at this. I'm using mysql connector .net to connect vb.net with
when I try to connect to my server through MySQL Connector/NET using SSL with
I am trying use MySql and Entity Framework, using Connector/Net 6.1 with this as
I am using MySQL database to work in ASP.NET MVC 3, i've already set
I'm using ASP.NET MVC. I'm also using the MySQL connector and providers to connect

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.