Пример #1
0
        public int Login(string UserName, string Password, string ValidateCode)
        {
            try
            {
                if (Request.Cookies["WrongOverTop"] != null)
                {
                    return(-3);
                }
                //var userinfo = new MODEL.UserInfo();
                //userinfo.Id = 1;
                //userinfo.UserName = "******";
                //userinfo.UserPwd = "123456";
                //userinfo.RegistDate = DateTime.Now;

                var userinfolist = _userinfo.Get().FirstOrDefault();

                if (UserName != userinfolist.UserName)
                {
                    return(-1);  //用户名不正确
                }
                else if (Password != userinfolist.UserPwd)
                {
                    if (Session["pwdWrong"] == null)
                    {
                        Session["pwdWrong"]  = 0;
                        Session["WrongTime"] = DateTime.Now;
                    }
                    else
                    {
                        Session["pwdWrong"] = Convert.ToInt32(Session["pwdWrong"]) + 1;
                    }
                    if (Convert.ToInt32(Session["pwdWrong"]) == 4 && DateTimeExtend.ExecDateDiff(DateTime.Now, Convert.ToDateTime(Session["WrongTime"])) <= 5)
                    {
                        Session.Remove("pwdWrong");
                        Session.Remove("WrongTime");
                        Response.Cookies.Add(new HttpCookie("WrongOverTop")
                        {
                            Expires = DateTime.Now.AddMinutes(10)
                        });
                        return(-3);
                    }
                    return(-2); //密码不正确
                }
                else
                {
                    var userCookie = new HttpCookie("UserCookie");
                    userCookie.Path = "/";
                    Guid guidUName = Guid.NewGuid();
                    AdminAuthorizeAttribute.userDic.Add(guidUName.ToString("N"), userinfolist.UserName);
                    userCookie.Value = guidUName.ToString("N");
                    HttpContext.Response.Cookies.Add(userCookie);
                    HttpContext.Response.Cookies.Add(new HttpCookie(userinfolist.UserName));
                    return(1);  //成功
                }
            }
            catch (Exception ex)
            {
                return(0);
            }
        }