Hi, this is my first time posting, found a lot of good answers and hope others may benefit from the solution to this question.
It may be something trivial, but I cannot get my login form to display "
Invalid username or password". I've set two accounts up on the remote MySQL server, both can log in fine however if I try misspelling the password/username or leave them blank completely, you can press the button as much as you want, it will not show any error message.
private void btnLogin_Click(object sender, EventArgs e)
{
try
{
dbConnect.login_initialise();
dbConnect.login_Open_Connection();
string login_query = "SELECT * FROM auth WHERE username=@username AND pass=@pass";
MySqlCommand cmd = new MySqlCommand(login_query, dbConnect.connection);
pass = txtPassword.Text;
hashed_pass = dbConnect.hash_value(pass);
cmd.Parameters.AddWithValue("@username", txtUsername.Text);
cmd.Parameters.AddWithValue("@pass", hashed_pass);
using (MySqlDataReader reader = cmd.ExecuteReader())
{
while (reader.Read())
{
if (reader.HasRows)
{
MessageBox.Show("Welcome!");
this.Hide();
mainMenu mm = new mainMenu();
mm.Show();
}
else
{
MessageBox.Show("Wrong Username or Password");
}
}
}
}
Weird part about this, most of the research I found on this, users cannot log in no matter what they try however I can log in fine just can't get it to display the error message.
To add a bit more detail, I have created two user accounts on the DB manually and logged in as both so it is clearly reading from the DB but if mistyped "obb" instead of "bob" for the username, it will not show any error message.
Hopefully someone may spot in seconds where I am going wrong, this has been a really confusing issue.
Many thanks for all your help!
(Slightly off-topic but may be related, I have a form that adds users and it does the same thing, keep clicking the button and no error message it simply does not every try connection and inserting the values)