请兄弟姐妹们帮我写的登陆代码减减肥~!
private void Button1_Click(object sender, System.EventArgs e)
{
if(Session["UserId"]!=null)
{
Response.Write("你现在的状态为已登陆,请不要重复登陆");
Response.End();
}
string UserName = CleanString.htmlInputText(this.UserName.Text);
string UserPass = CleanString.htmlInputText(System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(this.UserPass.Text,"md5"));
string Xyz = this.IntXyx.Text;
string XyzCode=System.Web.HttpContext.Current.Request.Cookies["checkCode"].Value;
if(Xyz!=XyzCode)
{
Response.Write("<script>alert('验证码输入有误!');history.go(-1);</script>");
}
SqlConnection conn=DB.createConnection();
conn.Open();
SqlCommand cmd=new SqlCommand("select * from UserTable where UserName='"+UserName+"'",conn);
SqlDataReader sdr=cmd.ExecuteReader();
if(sdr.HasRows)
{
sdr.Read();
string Mpass=sdr["UserPass"].ToString();
if(UserPass!=Mpass)
{
Response.Write("<script>alert('用户输入密码错误!');history.go(-1);</script>");
}
else
{
Session["UserId"]=sdr["UserId"].ToString();
sdr.Close();
SqlCommand cmdone=new SqlCommand("update UserTable set LoginTime='"+System.DateTime.Now.ToString()+"',LoginAdd='"+Request.UserHostAddress.ToString()+"' where UserName='"+UserName+"'",conn);
cmdone.ExecuteNonQuery();
Response.Redirect("../WebUser/Main.aspx");
}
}
else
{
Response.Write("<script>alert('没有此用户,请检查用户名是否正确!');history.go(-1);</script>");
}
conn.Close();
}
上面的代码执行过程中任何错误没有,可以正常合作,但老感觉太过"肥"了
而且不是很稳定,在极少情况下会出现连接池超出范围
请兄弟姐妹们,各位大哥帮帮忙,看看
五十分相送!!来者有分!!!!!!