如何检查c#中的用户名和密码?

时间:2014-01-30 09:42:08

标签: c# sql-server

在c#的登录页面中,如何检查用户名和密码是否与sqlserver中的用户名和密码匹配,以登录下一页? 我不想使用商店程序!

1 个答案:

答案 0 :(得分:0)

试试这个

 protected void loginButton_Click(object sender, EventArgs e)
{

    SqlConnection con = new SqlConnection();
    con.ConnectionString = "Data Source=.\\SQLEXPRESS;Initial Catalog=University;Integrated Security=True;Pooling=False";


    Int32 verify;
    string query1 = "Select count(*) from Login where ID='" + idBox.Text + "' and Password='" + passwordBox.Text + "' ";
    SqlCommand cmd1 = new SqlCommand(query1, con);
    con.Open();
    verify = Convert.ToInt32(cmd1.ExecuteScalar());
    con.Close();
    if (verify > 0)
    {
        Response.Redirect("succesful.aspx");
    }
    else
    {
        Response.Redirect("unsuccesful.aspx",true);
    }

}

但您需要使用存储过程来避免SQL INJECTION