登陆后台代码
protected void LoginSubmit_Click(object sender, EventArgs e)
{
string uname = name.Text.Trim();
string pwd = password.Text.Trim();
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
string sql = string.Format("select count(*) from userinfo where username='{0}' and password='{1}'", uname, pwd);
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
int a = (int)command.ExecuteScalar();
connection.Close();
if (a > 0) //登陆成功
{
Session["admin_user"] = uname;
}
else //登陆失败
{
Response.Write("<script> alert('用户名或密码错误,请重新输入')</script>");
}
}
注册后台代码
protected void Registersubmit_Click(object sender, EventArgs e)
{
string a1 = name.Text.Trim();
string a2 = password.Text.Trim();
string a3 = DateTime.Now.ToString();
SqlConnection connection = new SqlConnection(ConfigurationManager.ConnectionStrings["ConnectionString"].ToString());
string sql = string.Format("insert into register values( '{0}','{1}','{2}')", a1, a2, a3);
SqlCommand command = new SqlCommand(sql, connection);
connection.Open();
int count = (int)command.ExecuteNonQuery();
connection.Close();
if (count > 0)
{
Response.Write("<script>alert('注册成功')</script>");
}
else
{
Response.Write("<script>alert('注册失败,请您重试')</script>");
}
}