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");//学号存在 } }
public static string uNumPwdPost(string uNum, string uNumPwd) { string UNum = RegularExpressions.MyEncodeInputString(uNum.Trim()); string UNumPwd = RegularExpressions.MyEncodeInputString(uNumPwd.Trim()); if (CheckNum.CheckUserNum(UNum, uNumPwd)) { return("2"); } else { return("3");//学号验证失败 } }
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>"); } }
public static string uCheckPost(string uCheck) { string ucheck = RegularExpressions.MyEncodeInputString(uCheck.Trim()); if (HttpContext.Current.Session["check"] != null) { string check = HttpContext.Current.Session["check"].ToString(); if (check.ToUpper().Equals(ucheck.ToUpper())) { return("8"); } else { return("9");//验证码输入错误 } } else { return("10");//验证码生成错误 } }
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 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>"); } } }