Click here to Skip to main content
15,899,474 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Please help me with this code when they login right it still says username and password is wrong pl0x help.
C#
private void button3_Click(object sender, EventArgs e) 
{ 
  if (textBox1.Text == "Quinn") 
  { 
    if (textBox2.Text == "Qmanqtip12") 
    { 
      System.Threading.Thread.Sleep(4000); 
      MessageBox.Show("Welcome To AL7", "Login Succesfull", 
      MessageBoxButtons.OK, MessageBoxIcon.Information); 
      new Form2().Show(); 
      this.Hide(); 
    } 
    else 
    { 
      MessageBox.Show("Usename or Password Incorrect", "Error", 
      MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 
    } 
  } 

  MessageBox.Show("Usename or Password Incorrect", "Error", 
  MessageBoxButtons.OK, MessageBoxIcon.Error); 
}


What I have tried:

I have tried taking away thread sleeping but it no help
Posted
Updated 17-Dec-16 8:13am
v2

I think that above code should be changed :

private void button3_Click(object sender, EventArgs e) 
{ 
  if (textBox1.Text == "Quinn" && textBox2.Text == "Qmanqtip12") 
  {   
      System.Threading.Thread.Sleep(4000); 
      MessageBox.Show("Welcome To AL7", "Login Succesfull", 
      MessageBoxButtons.OK, MessageBoxIcon.Information); 
      new Form2().Show(); 
      this.Hide(); 
    
  else 
  { 
      MessageBox.Show("Usename or Password Incorrect", "Error", 
      MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 
  } 
}
 
Share this answer
 
v2
If you carefully check your flow, you will see that the second 'incorrect username or password' message box is outside any conditional branch (if)! That's the reason it always shows.
So adding the correct else will fix it, however you should not have that messages twice, but instead as about username and password in a single if, like this:
C#
if ((textBox1.Text == "Quinn") && (textBox2.Text == "Qmanqtip12"))
{ 
  System.Threading.Thread.Sleep(4000); 
  MessageBox.Show("Welcome To AL7", "Login Succesfull", 
  MessageBoxButtons.OK, MessageBoxIcon.Information); 
  new Form2().Show(); 
  this.Hide(); 
} 
else 
{ 
  MessageBox.Show("Usename or Password Incorrect", "Error", 
  MessageBoxButtons.OK, MessageBoxIcon.Exclamation); 
} 
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900