如何在asp.net webform中检查SQL Server中的用户名和密码对?

时间:2016-05-22 11:46:54

标签: c# asp.net sql-server

我的登录按钮的代码是

protected void LoginButton_Click(object sender, EventArgs e)
{
    string cs = WebConfigurationManager.ConnectionStrings["constr"].ConnectionString;

    using (SqlConnection connection = new SqlConnection(cs))
    {
        connection.Open();

        SqlCommand cmd = new SqlCommand("SELECT [Name], [Password] FROM [dbo].[user]", connection);

        using (SqlDataReader rdr = cmd.ExecuteReader())
        {
            while (rdr.Read())
            {
                // something goes there
            }

            if ()    // admin authentication 
            {
               Session["User_ID"] = nameTextBox.Text;
               Response.Redirect("~/AdminPanel.aspx");
            }
            else if()     // user authentication
            {
               Session["User_ID"] = nameTextBox.Text;
               Response.Redirect("~/UserPanel.aspx");
            }
        }
    }
}

Login表格中,我有UserIDUserNamePassword列。有nametextBox和passwordTextBox来获取UserName&密码。请帮助我,因为我遇到了用户登录的问题。

0 个答案:

没有答案