登录帮助C#登录信息不正确 [英] Login help C# login saying incorrect when info is

查看:53
本文介绍了登录帮助C#登录信息不正确的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当他们登录时,请帮助我使用此代码仍然说用户名和密码是错误的pl0x帮助。

Please help me with this code when they login right it still says username and password is wrong pl0x help.

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

推荐答案

我认为上面的代码应该改变:



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); 
  } 
}


如果仔细检查流量,您会看到第二个不正确的用户名或密码消息框是在任何条件分支之外(如果)!这就是它总是显示的原因。
所以添加正确的else会修复它,但是你不应该有两次这样的消息,而是在单个用户名和密码中,如下所示:

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:
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); 
} 


这篇关于登录帮助C#登录信息不正确的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆