简体   繁体   English

为什么我的登录表单允许用户使用正确的用户名登录,但密码不正确?

[英]Why my login form allowing users to login with correct USERNAME, but incorrect PASSWORD?

private void button1_Click(object sender, EventArgs e)
{
    SqlConnection con = new SqlConnection(Sqlconnection.connectionString);
    SqlCommand cmd = new SqlCommand("select * from tbllogin where @username='" + txtname.Text + "' and @password='" + txtpass.Text + "'");
    cmd.Parameters.AddWithValue("@username", txtname.Text);
    cmd.Parameters.AddWithValue("@password", txtpass.Text);
    cmd.Connection = con;
    con.Open();
    SqlDataReader dr = cmd.ExecuteReader();
    if (dr.HasRows)
    {

        MessageBox.Show("Login  Successfully. ..!");
        main m = new main();
        this.Hide();
        m.Show();
    }
 else
    {
       MessageBox.Show("Login Failed....!");
    }
    con.Close();

}

检查您的SELECT语句:

SqlCommand cmd = new SqlCommand("select * from tbllogin where username=@username and password=@password");

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 我的登录始终成功,无论用户名或密码正确/错误 - my login is always successful, whether it is correct/wrong username or password 为什么我的登录功能让用户使用随机密码登录? - Why my login function let users login with a random password? 输入正确的用户名和密码后,ASP登录无法正常工作 - ASP login doesn't work when correct username and password are entered 在登录表单中检查用户名 - Check a username in a login form mvc3登录表单错误的用户名和密码消息 - mvc3 login form wrong username and password message POST asp.net表单用户名和密码以外部HTTPS登录 - POST asp.net form username and password to an external HTTPS login 在登录表单上输入用户名和密码后,处理登录表单并显示主表单 - Dispose login form and show main form after username and password are entered on login form 为什么登录控件C#为任何用户名和密码提供身份验证 - Why Login control C# gives authentications to any username and a password 需要在 C# 中使用用户名和密码创建登录窗口,但是当我输入不正确的用户名或密码时,出现错误 - Need to make a login window with username and password in C# but when i introduce an incorrect username or password i get an error 尝试创建一个登录页面,如果用户名正确,它还会显示“只有密码错误” - Trying to create a Login page where it also shows that "Only password is wrong" if username is correct
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM