public ArrayList login() { string msg = ""; //对于这些东西,实际项目一定要做防sql注入处理,尽量使用ORM方法操作,不要直接SQL string userName = ctx.Request["username"]; string Password = ctx.Request["password"]; //验证登录信息,如果验证通过则返回当前用户对象的安全上下文信息,并记录失败次数 accctx = AccountsPrincipal.ValidateLogin(userName, Password); HttpCookie ErrorCookie = new HttpCookie("PassErrorCount"); ErrorCookie.Expires = DateTime.Now.AddDays(1); HttpCookie userLoginIdCookie = new HttpCookie("userLoginId"); if (accctx == null)//登录信息不对 { msg = "登陆失败: " + userName; if (HttpContext.Current.Request.Cookies["PassErrorCount"] != null && (HttpContext.Current.Request.Cookies["PassErrorCount"].Value != "")) { int PassErroeCount = Convert.ToInt32(HttpContext.Current.Request.Cookies["PassErrorCount"].Value); ErrorCookie.Value = Convert.ToString(PassErroeCount + 1); HttpContext.Current.Response.Cookies.Add(ErrorCookie); } else { ErrorCookie.Value = "1"; HttpContext.Current.Response.Cookies.Add(ErrorCookie); } Arraylists.Add(msg); Arraylists.Add(false); } else { //用memcache+cookie或者redis+cookie代替之。 //立即分配一个标志,Guid。把标志作为 mm存储数据的key,把用户对象放到 mm。 把guid写到客户端cookie里面去。 string userLoginId = Guid.NewGuid().ToString(); //把用户的数据写到mm CacheFactory.Cache().WriteCache <AccountsPrincipal>(accctx, userLoginId, DateTime.Now.AddMinutes(20)); //往客户端写入cookie userLoginIdCookie.Value = userLoginId; ctx.User = accctx; HttpContext.Current.Response.Cookies.Add(userLoginIdCookie); //ctx.Session["accctx"] = accctx; msg = "登录成功,页面跳转中!"; Arraylists.Add(msg); Arraylists.Add(true); if (ErrorCookie != null) { ErrorCookie.Expires = DateTime.Now.AddDays(-1); } } return(Arraylists); }
public override ArrayList login() { string msg = ""; //对于这些东西,实际项目一定要做防sql注入处理,尽量使用ORM方法操作,不要直接SQL string userName = ctx.Request["username"]; string Password = ctx.Request["password"]; //验证登录信息,如果验证通过则返回当前用户对象的安全上下文信息,并记录失败次数 accctx = AccountsPrincipal.ValidateLogin(userName, Password); HttpCookie ErrorCookie = new HttpCookie("PassErrorCount"); ErrorCookie.Expires = DateTime.Now.AddDays(1); if (accctx == null)//登录信息不对 { msg = "登陆失败: " + userName; if (HttpContext.Current.Request.Cookies["PassErrorCount"] != null && (HttpContext.Current.Request.Cookies["PassErrorCount"].Value != "")) { int PassErroeCount = Convert.ToInt32(HttpContext.Current.Request.Cookies["PassErrorCount"].Value); ErrorCookie.Value = Convert.ToString(PassErroeCount + 1); HttpContext.Current.Response.Cookies.Add(ErrorCookie); } else { ErrorCookie.Value = "1"; HttpContext.Current.Response.Cookies.Add(ErrorCookie); } Arraylists.Add(msg); Arraylists.Add(false); } else { ctx.User = accctx; ctx.Session["accctx"] = accctx; msg = "登录成功,页面跳转中!"; Arraylists.Add(msg); Arraylists.Add(true); if (ErrorCookie != null) { ErrorCookie.Expires = DateTime.Now.AddDays(-1); } } return(Arraylists); }
public override ArrayList login() { string msg = ""; //对于这些东西,实际项目一定要做防sql注入处理,尽量使用ORM方法操作,不要直接SQL string userName = ctx.Request["username"]; string Password = ctx.Request["password"]; //验证登录信息,如果验证通过则返回当前用户对象的安全上下文信息,并记录失败次数 accctx = AccountsPrincipal.ValidateLogin(userName, Password); if (accctx == null)//登录信息不对 { msg = "登陆失败: " + userName; if ((ctx.Session["PassErrorCount"] != null) && (ctx.Session["PassErrorCount"].ToString() != "")) { int PassErroeCount = Convert.ToInt32(ctx.Session["PassErrorCount"]); ctx.Session["PassErrorCount"] = PassErroeCount + 1; } else { ctx.Session["PassErrorCount"] = 1; } Arraylists.Add(msg); Arraylists.Add(false); } else { ctx.User = accctx; ctx.Session["accctx"] = accctx; msg = "登录成功,页面跳转中!"; Arraylists.Add(msg); Arraylists.Add(true); } return(Arraylists); }