/// <summary> /// 判断是否在线 /// </summary> /// <returns></returns> public string WhetherOnline() { string userid = null; HttpCookie cookies = HttpContext.Current.Request.Cookies["ISAccountCookie"]; if (cookies != null) { string uname = cookies["username"].ToString(); string upwd = cookies["userpwd"].ToString(); string isAutoLogin = cookies["isAutoLogin"].ToString(); int uright = int.Parse(cookies["uright"].ToString()); string uid = cookies["uid"].ToString(); yonghuModel yhm = new yonghuDAL().GetModelByUsername(uname); #region 验证是否该用户 作用:防止黑客通过Cookie入侵 string uid2 = new MD5Encrypt().GetMD5(yhm.nvc_username + yhm.nc_uid); if (uid == uid2 && uright == yhm.int_right) { #region 验证密码 string pwd2 = new MD5Encrypt().GetMD5(upwd + yhm.nvc_username); if (pwd2 == yhm.nvc_pwd) { userid = yhm.nc_uid; } else { HttpContext.Current.Response.Write("<script>javascript:alert('请登录!原因:您的密码已过期。');top.location.replace('../account/login.aspx');</script>"); } #endregion } else { HttpContext.Current.Response.Write("<script>javascript:alert('请登录!原因:您未登录。');top.location.replace('../account/login.aspx');</script>"); } #endregion } else { HttpContext.Current.Response.Write("<script>javascript:alert('请登录!原因:您未登录。');top.location.replace('../account/login.aspx');</script>"); } return(userid); }
/// <summary> /// 登录 /// </summary> /// <param name="isReamber">是否记住</param> /// <param name="uname">用户名</param> /// <param name="pwd">密码</param> protected void login(string isReamber, string uname, string pwd) { bool isexist = new yonghuDAL().ExistsUserName(uname); if (isexist == true) { yonghuModel yhm = new yonghuDAL().GetModelByUsername(uname); string pwd2 = new MD5Encrypt().GetMD5(pwd + uname); if (pwd2 == yhm.nvc_pwd) { string[,] array = new string[5, 2]; array[0, 0] = "username"; array[0, 1] = yhm.nvc_username; array[1, 0] = "userpwd"; array[1, 1] = pwd; array[2, 0] = "isAutoLogin"; array[2, 1] = isReamber; array[3, 0] = "uright"; array[3, 1] = yhm.int_right.ToString(); array[4, 0] = "uid"; array[4, 1] = new MD5Encrypt().GetMD5(uname + yhm.nc_uid); new SetCookie().CreateCookie("ISAccountCookie", 0, 8, 0, 0, array); new SetCookie().CreateCookie("ISReamberAccountCookie", 5, 0, 0, 0, array); Response.Redirect(domain + "/default.aspx"); } else { loginErrorMsg = "密码错误。"; loginUname = uname; loginUpwdStyle = "loginError"; loginFocus = "userpwd"; } } else { loginErrorMsg = "用户名不存在。"; loginUnameStyle = "loginError"; loginFocus = "username"; } }
protected void Page_Load(object sender, EventArgs e) { string caozuo = null; if (!string.IsNullOrEmpty(Request.Form["action"]))//获取数据类型 { caozuo = Request.Form["action"]; } if (caozuo == "Register") { #region 注册 #region 用户名 string uname = null; if (!string.IsNullOrEmpty(Request.Form["CreateUsername"]))//获取数据类型 { string un = Request.Form["CreateUsername"]; if (un.Length > 0 && un.Length <= 20) { if (Regex.IsMatch(un, @"^([\u4e00-\u9fa5]|[a-zA-Z]|[0-9]|-){0,}$") || Regex.IsMatch(un, @"^[_\.0-9a-zA-Z-]+@([0-9a-zA-Z][0-9a-zA-Z-]+\.)+[a-zA-Z]{2,4}$")) { uname = un; } } } #endregion #region 密码 string pwd = null; if (!string.IsNullOrEmpty(Request.Form["CreatePassword"]))//获取数据类型 { string up = Request.Form["CreatePassword"]; if (up.Length > 6 && up.Length <= 16 && up != "123456" && up != "654321" && up != "111222") { pwd = up; } } #endregion #region 重复密码 string repwd = null; if (!string.IsNullOrEmpty(Request.Form["CreateRePassword"]))//获取数据类型 { string urd = Request.Form["CreateRePassword"]; if (urd == pwd) { repwd = urd; } } #endregion #region 操作 string action = null; if (!string.IsNullOrEmpty(Request.Form["RegisterSubmit"]))//获取数据类型 { action = Request.Form["RegisterSubmit"]; } #endregion if (pwd == repwd && action == "创建账户" && string.IsNullOrEmpty(uname) != null) { //添加一条记录 yonghuModel yhm = new yonghuModel(); yhm.nvc_username = uname; yhm.nvc_pwd = new MD5Encrypt().GetMD5(pwd + uname); yhm.int_right = 1; bool isInsertOk = new yonghuDAL().Add(yhm); if (isInsertOk == true) { Response.Write("<script>javascript:alert('注册成功!');window.parent.location.reload();</script>"); } } else { Response.Write("<script>javascript:alert('注册失败!请重试!');</script>"); } #endregion Response.End(); } Page.DataBind(); }