public void CHKLogin(string userName, string passWord)
        {
            passWord = passWord.GetAdminMD5();
            SysAdmin user = Entity.SysAdmin.Where(n => n.UserName == userName && n.PassWord == passWord && n.AgentId == 0).FirstOrDefault();

            if (user != null)
            {
                if (user.State == 0)
                {
                    Response.Redirect("/manage/login.html?IsError=2");
                    return;
                }
                DateTime now                 = DateTime.Now;
                string   neiw                = System.Configuration.ConfigurationManager.AppSettings["key"].ToString();
                string   IsLockScreen        = "0";//锁屏状态 登录时默认是不锁屏(1为锁屏,0为不锁屏)
                string   UserNameAndPassWord = LokFuEncode.LokFuAuthcodeEncode(string.Format("{0}|{1}|{2}|{3}", user.Id, userName, now.ToString("yyyy-MM-dd HH:mm:ss"), IsLockScreen), neiw);
                Response.Cookies.SetAdmin(UserNameAndPassWord);
                user.LoginTimes++;
                user.LastTime = now;
                user.LoginIp  = Tools.GetIp();
                if (!user.QQNum.IsNullOrEmpty())
                {
                    user.QQState = 1;
                }
                Entity.SaveChanges();
                Response.Redirect("/manage/Home/Index.html");
                return;
            }
            else
            {
                Response.Redirect("/manage/login.html?IsError=1");
            }
            return;
        }
        public void LockScreenON()
        {
            string neiw = System.Configuration.ConfigurationManager.AppSettings["key"];
            string UserNameAndPassWord = LokFuEncode.LokFuAuthcodeEncode(string.Format("{0}|{1}|{2}|{3}", AdminUser.Id, AdminUser.UserName, AdminUser.LastTime.Value.ToString("yyyy-MM-dd HH:mm:ss"), "1"), neiw);

            Response.Cookies.SetAdmin(UserNameAndPassWord);
        }
        public void CHKLogin(string userName, string passWord, string saveUsername)
        {
            if (!saveUsername.IsNullOrEmpty())
            {
                var cookie = new System.Web.HttpCookie("saveUsername");
                cookie.Values.Add("saveUsername", userName);
                cookie.Expires = DateTime.Now.AddMonths(1);
                this.HttpContext.Response.Cookies.Add(cookie);
            }
            passWord = passWord.GetAdminMD5();
            SysAdmin user1 = Entity.SysAdmin.Where(o => o.UserName == userName && o.PassWord == passWord).FirstOrDefault();
            SysAdmin user  = Entity.SysAdmin.Where(n => n.UserName == userName && n.PassWord == passWord && n.AgentId > 0).FirstOrDefault();

            if (user != null)
            {
                if (user.State == 0)
                {
                    Response.Redirect("/agent/login.html?IsError=2");
                    return;
                }
                SysAgent SysAgent = Entity.SysAgent.FirstOrNew(n => n.Id == user.AgentId);
                if (SysAgent.Id.IsNullOrEmpty())
                {
                    Response.Redirect("/agent/login.html?IsError=4");
                    return;
                }
                if (SysAgent.State != 1)
                {
                    Response.Redirect("/agent/login.html?IsError=4");
                    return;
                }
                DateTime now  = DateTime.Now;
                string   neiw = System.Configuration.ConfigurationManager.AppSettings["key"].ToString();
                string   UserNameAndPassWord = LokFuEncode.LokFuAuthcodeEncode(string.Format("{0}|{1}|{2}", user.Id, userName, now.ToString("yyyy-MM-dd HH:mm")), neiw);
                Response.Cookies.SetAgent(UserNameAndPassWord);
                user.LoginTimes++;
                user.LastTime = now;
                user.LoginIp  = Tools.GetIp();
                Entity.SaveChanges();
                Response.Redirect("/agent/Home/Index.html");
                return;
            }
            else
            {
                Response.Redirect("/agent/login.html?IsError=1");
            }
            return;
        }
        //方式1:普通长轮询 Ajax方式,服务端运用System.Threading.Thread,客户端运用无限Ajax请求
        //巨大缺点:采用Thread hold住程序会严重占用资源,影响处理请求并发。
        //方式2:ajax长连接,服务端无Thread,客户端Ajax采用timeout,隔时无限加载。
        //缺点:产生很多无效请求,包含过多的http头部信息,增加数据量。
        public void GetQrCodeLogin(string Sceneid)
        {
            UserLoginSceneid Log = Entity.UserLoginSceneid.FirstOrNew(n => n.Sceneid == Sceneid);

            if (Log.AddTime.AddMinutes(5) < DateTime.Now)//失效
            {
                Response.Cookies.SetQRCodeSceneid(string.Empty);
                Response.Write("E0");
                return;
            }
            if (Log.UId.IsNullOrEmpty())        //未登录
            {
                if (!Log.Token.IsNullOrEmpty()) //已扫码
                {
                    Response.Write("E8");
                    return;
                }
                else
                {
                    Response.Write("E9");
                    return;
                }
            }
            Users BaseUsers = Entity.Users.FirstOrNew(n => n.Id == Log.UId);

            if (BaseUsers.Id.IsNullOrEmpty())
            {
                Response.Write("E1");
                return;
            }
            string neiw = System.Configuration.ConfigurationManager.AppSettings["key"].ToString();
            string UserNameAndPassWord = LokFuEncode.LokFuAuthcodeEncode(string.Format("{0}|{1}|{2}", BaseUsers.Id, BaseUsers.UserName, BaseUsers.PassWord), neiw);

            Response.Cookies.SetUsers(UserNameAndPassWord);
            BaseUsers.LoginErr = 0;
            Entity.SaveChanges();
            //清除扫码记录cookie,删除临时保存的数据库二维码参数
            Response.Cookies.SetQRCodeSceneid(string.Empty);
            Entity.DeleteObject(Log);
            Entity.SaveChanges();
            Response.Write("OK");
            Response.End();
        }
 public void CHK_PWD(string PassWord)
 {
     AdminUser = GetAdmin();
     if (AdminUser == null)
     {
         return;
     }
     PassWord = PassWord.GetAdminMD5();
     if (PassWord.Equals(AdminUser.PassWord))
     {
         string neiw = System.Configuration.ConfigurationManager.AppSettings["key"];
         //DateTime Now = DateTime.Now;
         //AdminUser.LastTime = Now;
         //Entity.SaveChanges();
         string UserNameAndPassWord = LokFuEncode.LokFuAuthcodeEncode(string.Format("{0}|{1}|{2}|{3}", AdminUser.Id, AdminUser.UserName, AdminUser.LastTime.Value.ToString("yyyy-MM-dd HH:mm:ss"), "0"), neiw);
         Response.Cookies.SetAdmin(UserNameAndPassWord);
         Response.Write("1");
     }
     else
     {
         Response.Write("0");
     }
 }
        public void CHKLogin(string userName, string passWord, string Code)
        {
            Response.AddHeader("content-type", "application/json");
            if (Code.ToUpper() != Session.GetCheckCode())
            {
                Response.Write("{\"msg\":\"E0\",\"log\":\"0\"}");
                return;
            }
            Session.ClearCheckCode();
            if (userName.IsNullOrEmpty() || passWord.IsNullOrEmpty())
            {
                return;
            }
            string Sceneid = Request.Cookies.GetQRCodeSceneid();

            if (!Sceneid.IsNullOrEmpty())
            {
                Sceneid = Sceneid.Split(',')[0];
            }
            string key = Sceneid.GetMD5();
            string un  = XXCode.Decrypt(userName, key);
            string pwd = XXCode.Decrypt(passWord, key);

            pwd = pwd.GetMD5();
            Users baseUsers = Entity.Users.FirstOrDefault(n => n.UserName == un);

            if (baseUsers == null)//用户不存在
            {
                Response.Write("{\"msg\":\"E1\",\"log\":\"0\"}");
                return;
            }
            if (baseUsers.State != 1)
            {
                Response.Write("{\"msg\":\"E3\",\"log\":\"0\"}");
                return;
            }
            if (baseUsers.LoginLock == 1)//临时锁定
            {
                Response.Write("{\"msg\":\"E4\",\"log\":\"0\"}");
                return;
            }
            if (baseUsers.PassWord != pwd)
            {
                SysSet SysSet = Entity.SysSet.FirstOrNew();
                //系统统一修改标识SAME001
                baseUsers.LoginErr++;
                if (baseUsers.LoginErr >= SysSet.LoginLock)
                {
                    baseUsers.LoginLock = 1;
                }
                Entity.SaveChanges();
                int LoginErr = SysSet.LoginLock - baseUsers.LoginErr;
                Response.Write("{\"msg\":\"E2\",\"log\":\"" + LoginErr + "\"}");
                return;
            }
            string neiw = System.Configuration.ConfigurationManager.AppSettings["key"].ToString();
            string UserNameAndPassWord = LokFuEncode.LokFuAuthcodeEncode(string.Format("{0}|{1}|{2}", baseUsers.Id, un, pwd), neiw);

            Response.Cookies.SetUsers(UserNameAndPassWord);
            baseUsers.LoginErr = 0;
            Entity.SaveChanges();
            Response.Write("{\"msg\":\"OK\",\"log\":\"0\"}");
            return;
        }