asp.net网站根据用户注册信息完成登录示例
protected void btnLoad_Click(object sender, ImageClickEventArgs e)
{
HttpCookie cookie = Request.Cookies["CheckCode"];
if (String.Compare(cookie.Value, txtVali.Text, true) != 0)
{ Response.Write("<script lanuage=javascript>alert('验证码错误');location='javascript:history.go(-1)'</script>");
} else
{
DataSet ds = DB.reDs("select * from tb_HuenLian where UserName='" + txtUid.Text.Trim() + "' and PassWord='" + txtPwd.Text.Trim() + "'");
int i = this.checkLogin(txtUid.Text, txtPwd.Text);
if (i > 0)
{
Session["id"] = ds.Tables[0].Rows[0][0].ToString();
Session["UserName"] = this.txtUid.Text;
Session["PassWord"] = this.txtPwd.Text;
Page.Response.Redirect("login.aspx");//登录成功登录该网页
}
else
{
Response.Write("<script lanuage=javascript>alert('用户名称或密码错误!');location='javascript:history.go(-1)'</script>");
}
}
}//codego.net/tags/11/1/
public int checkLogin(string loginName, string loginPwd)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["conn"]);
SqlCommand myCommand = new SqlCommand("select count(*) from tb_HuenLian where UserName=@loginName and PassWord=@loginPwd", con);
myCommand.Parameters.Add(new SqlParameter("@loginName", SqlDbType.NVarChar, 20));
myCommand.Parameters["@loginName"].Value = loginName;
myCommand.Parameters.Add(new SqlParameter("@loginPwd", SqlDbType.NVarChar, 50));
myCommand.Parameters["@loginPwd"].Value = loginPwd;
myCommand.Connection.Open();
int i = (int)myCommand.ExecuteScalar();
myCommand.Connection.Close();
return i;
}
protected void btnLoad_Click(object sender, ImageClickEventArgs e)
{
HttpCookie cookie = Request.Cookies["CheckCode"];
if (String.Compare(cookie.Value, txtVali.Text, true) != 0)
{ Response.Write("<script lanuage=javascript>alert('验证码错误');location='javascript:history.go(-1)'</script>");
} else
{
DataSet ds = DB.reDs("select * from tb_HuenLian where UserName='" + txtUid.Text.Trim() + "' and PassWord='" + txtPwd.Text.Trim() + "'");
int i = this.checkLogin(txtUid.Text, txtPwd.Text);
if (i > 0)
{
Session["id"] = ds.Tables[0].Rows[0][0].ToString();
Session["UserName"] = this.txtUid.Text;
Session["PassWord"] = this.txtPwd.Text;
Page.Response.Redirect("login.aspx");//登录成功登录该网页
}
else
{
Response.Write("<script lanuage=javascript>alert('用户名称或密码错误!');location='javascript:history.go(-1)'</script>");
}
}
}//codego.net/tags/11/1/
public int checkLogin(string loginName, string loginPwd)
{
SqlConnection con = new SqlConnection(ConfigurationManager.AppSettings["conn"]);
SqlCommand myCommand = new SqlCommand("select count(*) from tb_HuenLian where UserName=@loginName and PassWord=@loginPwd", con);
myCommand.Parameters.Add(new SqlParameter("@loginName", SqlDbType.NVarChar, 20));
myCommand.Parameters["@loginName"].Value = loginName;
myCommand.Parameters.Add(new SqlParameter("@loginPwd", SqlDbType.NVarChar, 50));
myCommand.Parameters["@loginPwd"].Value = loginPwd;
myCommand.Connection.Open();
int i = (int)myCommand.ExecuteScalar();
myCommand.Connection.Close();
return i;
}
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货