[英]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.