62,046
社区成员
发帖
与我相关
我的任务
分享
//登录按钮
protected void Button1_Click(object sender, EventArgs e)
{
string checkcode = Session["CheckCode"].ToString();
if (this.TextBox3.Text == checkcode)
{
if (RadioButtonList1.SelectedIndex == 0)
{
string name = txb_Uname.Text;
string pwd = FormsAuthentication.HashPasswordForStoringInConfigFile(txb_Upwd.Text, "MD5");
string con_access = ConfigurationManager.AppSettings["accessCon"].ToString();
OleDbConnection conn = new OleDbConnection(con_access);
string sql = "select * from T_USER where U_NAME='" + name + "' and U_PWD='" + pwd + "'";
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
OleDbDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
if (CheckBox1.Checked == true)
{
Response.Cookies["username"].Expires = DateTime.Now.AddDays(30);
Response.Cookies["userpwd"].Expires = DateTime.Now.AddDays(30);
Response.Cookies["username"].Value = txb_Uname.Text.Trim();
Response.Cookies["userpwd"].Value = txb_Upwd.Text.Trim();
}
//Response.Redirect("Default.aspx");
if (Session["url"] == null)
{
Session["username"] = txb_Uname.Text.Trim();
Response.Redirect("Default.aspx");
}
else
{
Session["username"] = txb_Uname.Text.Trim();
Response.Redirect(System.Web.HttpUtility.UrlDecode(Session["url"].ToString()));
}
}
else
{
Label1.Text = "用户名或密码错误";
}
dr.Close();
conn.Close();
}
if (RadioButtonList1.SelectedIndex == 1)
{
if (txb_Uname.Text.Trim().Equals("admin") && txb_Upwd.Text.Trim().Equals("admin"))
{
Response.Redirect("AdminDefault.aspx");
}
else
{
Label1.Text = "您不是管理员,请选择普通用户登录!";
}
}
}
else
{
Label1.Text = "验证码错误,请重新输入!";
}
}
protected void txb_Uname_TextChanged(object sender, EventArgs e)
{
if (Request.Cookies["username"] != null)
{
if (Request.Cookies["username"].Value.Equals(txb_Uname.Text.Trim()))
{
txb_Upwd.Attributes["value"] = Request.Cookies["userpwd"].Value;
}
else
{
txb_Upwd.Text = "";
}
}
}
protected void Page_Load(object sender, EventArgs e)
{
Session["url"] = Request.UrlReferrer;
if (Session["username"] == null)
{
Panel2.Visible = false;
}
else
{
Panel1.Visible = false;
LinkButton1.Text = Session["username"].ToString();
}
//Session["url"] = Request.UrlReferrer;
dlBind();
}
//点击用户名进入会员中心
protected void LinkButton1_Click(object sender, EventArgs e)
{
Response.Redirect("MemberCenter.aspx");
}
//退出登录
protected void LinkButton2_Click(object sender, EventArgs e)
{
FormsAuthentication.SignOut(); //清除验证信息
Session.Clear(); //清除Session的内存
Session.Abandon(); //取消会话状态
Response.Redirect("Default.aspx");
}
protected void Page_Load(object sender, EventArgs e)
{
//string user = Page.Session["username"].ToString();
if (Session["username"] != null)
{
string con_access = ConfigurationManager.AppSettings["accessCon"].ToString();
OleDbConnection conn = new OleDbConnection(con_access);
string sql = "select U_NAME,U_MAJOR,U_POINTS from T_USER where U_NAME='"+Session["username"]+"'";
OleDbCommand cmd = new OleDbCommand(sql, conn);
conn.Open();
OleDbDataReader dr = cmd.ExecuteReader();
if (dr.Read())
{
Label1.Text = dr[0].ToString();
Label2.Text = dr[1].ToString();
Label3.Text = dr[2].ToString();
}
dr.Close();
conn.Close();
}
else
{
Response.Redirect("error.aspx");
}
}