protected void check(object sender, EventArgs e) { string stunumStr = RegularExpressions.MyEncodeInputString(worknum.Value.Trim()); string pwdStr = RegularExpressions.MyEncodeInputString(pwd.Value.Trim()); int isStuNumExsit = BADL_User.IsStunumExsit(stunumStr) ? 0 : 1;//0:学号存在,1:学号不存在 if (CheckNum.CheckUserNum(stunumStr, pwdStr)) { Session["stuNum"] = stunumStr; string uname = BADL_User.GetUserName(stunumStr); string umail = BADL_User.GetUserMail(stunumStr); if (isStuNumExsit == 1) { Response.Write("<script>alert('该学号未注册,请注册');self.location='register.aspx'</script>"); } else if (isStuNumExsit == 0) { HttpCookie cookies = new HttpCookie("getUser"); cookies.Value = uname + "+" + umail; cookies.Expires = System.DateTime.Now.AddDays(1); Response.Cookies.Add(cookies); Response.Redirect("resetPwd.aspx"); } } else { Response.Write("<script>alert('验证失败,学号或上网密码错误')</script>"); } }
public static string uMailPost(string uMail) { string UMail = RegularExpressions.MyEncodeInputString(uMail.Trim()); if (!BADL_User.IsMailExsit(UMail)) { return("6"); } else { return("7");//邮箱存在 } }
public static string uNamePost(string uName) { string UName = RegularExpressions.MyEncodeInputString(uName.Trim()); if (!BADL_User.IsNameExsit(UName)) { return("4"); } else { return("5");//昵称存在 } }
public static string uNumPost(string uNum) { string UNum = RegularExpressions.MyEncodeInputString(uNum.Trim()); if (!BADL_User.IsStunumExsit(UNum)) { return("0"); } else { return("1");//学号存在 } }
protected void Log(object sender, EventArgs e) { En_User user = BADL_User.Login(RegularExpressions.MyEncodeInputString(uInfo.Value.Trim()), Md5.MD5_encrypt(RegularExpressions.MyEncodeInputString(uPwd.Value.Trim()))); if (user != null) { Session["User"] = user; //将user写入session if (!BADL_User.ChangeLogInfor(user.UNum, DateTime.Now)) //更新登录时间异常 { Response.Write("<script>alert('更新登录时间异常,登录失败')</script>"); } else { HttpCookie cookieUserName = new HttpCookie("UserName");//将用户名写入cookie cookieUserName.Value = user.UName; cookieUserName.Expires = System.DateTime.Now.AddDays(1); Response.Cookies.Add(cookieUserName); string userRole = BADL_User.GetUserRole(user.UNum); //得到用户的角色 Session["UserRole"] = userRole; //将userRole写入session,一般用户的role为"0" HttpCookie cookieUserRole = new HttpCookie("UserRole"); //将userRole写入cookie cookieUserRole.Value = userRole; cookieUserRole.Expires = System.DateTime.Now.AddDays(1); Response.Cookies.Add(cookieUserRole); if (savePwd.Checked)//如果用户记住密码,将学号和登录密码写入cookie { HttpCookie cookieUser = new HttpCookie("UserLog"); cookieUser.Value = user.UNum + "+" + Md5.MD5_encrypt(uPwd.Value); cookieUser.Expires = System.DateTime.Now.AddDays(1); Response.Cookies.Add(cookieUser); } Response.Redirect("index.aspx"); } } else { Response.Write("<script>alert('登录失败,用户名或密码不正确')</script>"); } }
protected void rePwd(object sender, EventArgs e) { string rePwd = RegularExpressions.MyEncodeInputString(pwd.Value.Trim()); string rePwd1 = RegularExpressions.MyEncodeInputString(pwd1.Value.Trim()); if (rePwd.Equals(rePwd1)) { if (BADL_User.ChangePwd(Md5.MD5_encrypt(rePwd), Session["stuNum"].ToString())) { Response.Redirect("login.aspx"); } else { Response.Write("<script>alert('更新密码异常');</script>"); } } else { Response.Write("<script>alert('密码不一致');</script>"); } }
protected void OnInit(object sender, EventArgs e)//如果有cookie或session的话,已是登录状态,直接跳转 { if (Session["User"] == null) { if (Request.Cookies["UserLog"] != null)//session过期,查看cookie是否存在 { string[] message = Request.Cookies["UserLog"].Value.Split('+'); if (message.Length == 2) { string worknum = message[0]; string password = message[1]; if (BADL_User.CheckCookies(worknum, password)) //判断cookie的真实性 { Session["User"] = BADL_User.Login(worknum); //写入session Response.Redirect("index.aspx"); } } } } else//session未过期,直接登录,跳转到首页 { Response.Redirect("index.aspx"); } }
protected void uRegister(object sender, EventArgs e) { string unum = RegularExpressions.MyEncodeInputString(uNum.Value.Trim()); string unumpwd = RegularExpressions.MyEncodeInputString(uNumPwd.Value.Trim()); string uname = RegularExpressions.MyEncodeInputString(uName.Value.Trim()); string upwd = RegularExpressions.MyEncodeInputString(pwd.Value.Trim()); string upwd1 = RegularExpressions.MyEncodeInputString(pwd1.Value.Trim()); string umail = RegularExpressions.MyEncodeInputString(uMail.Value.Trim()); string ucheck = RegularExpressions.MyEncodeInputString(uCheck.Value.Trim()); string check = HttpContext.Current.Session["check"].ToString(); if (HttpContext.Current.Session["check"] == null)//判断验证码 { Response.Write("<script>alert('验证码生成错误')</script>"); } else if (!CheckNum.CheckUserNum(unum, unumpwd)) { Response.Write("<script>alert('学号或上网密码错误')</script>"); } else if (!upwd.Equals(upwd1)) { Response.Write("<script>alert('密码不一致')</script>"); } else if (!check.ToUpper().Equals(ucheck.ToUpper())) { Response.Write("<script>alert('验证码输入错误')</script>"); } else { En_User eu = new En_User(); eu.UNum = unum; eu.UName = uname; eu.UPwd = Md5.MD5_encrypt(upwd1); eu.UMail = umail; eu.RegisterTime = DateTime.Now; eu.LastLogin = DateTime.Now; eu.State = 0; int blank = BADL_User.IsBlankReg(eu);//判断字段长度 if (blank != 5) { Response.Write("<script>alert('字段长度不符')</script>"); } else if (BADL_User.IsStunumExsit(unum)) { Response.Write("<script>alert('学号存在')</script>"); } else if (BADL_User.IsNameExsit(uname)) { Response.Write("<script>alert('昵称存在')</script>"); } else if (BADL_User.InsertUser(eu)) { Response.Redirect("login.aspx");//注册成功,跳转到登录界面 } else { Response.Write("<script>alert('注册异常')</script>"); } } }