/// <summary>
        /// 登入驗證,若成功後,將登入資訊存入Cookie
        /// </summary>
        /// <param name="account"></param>
        /// <param name="password">未加密過的密碼</param>
        /// <returns></returns>
        public override bool Login(string account, string password)
        {
            //取得帳號資料
            var userDetail      = User.FetchAdminUserDetail(account);
            var encryptPassword = Md5.Encrypt(password);

            //檢查使用者的密碼
            if (string.IsNullOrEmpty(userDetail.EncryptPassword) || !userDetail.EncryptPassword.Equals(encryptPassword))
            {
                return(false);
            }

            var principal = new ManagerPrincipal(userDetail.Account);

            //HttpContext.Current.User = principal;
            //Identity = HttpContext.Current.User.Identity as ManagerIdentity;
            //註冊Cookies
            //AddCookie(userDetail);
            AddCookie(principal);
            CacheProvider.Insert(userDetail.Account, principal);

            //System.Diagnostics.Debug.WriteLine(CurrentUser);
            //更新最後登入時間及IP
            ////userDetail.CurrentLoginIp = Request.ServerVariables["REMOTE_ADDR"];
            //dataProvider.UpdateAdminUserLastLogin(userDetail);
            return(true);
        }
        public bool Login(UserParameter param)
        {
            //取得帳號資料
            var userDetail = User.FetchAdminUserDetail(param.User.Account);

            if (userDetail.Status == 2)
            {
                return(false);
            }

            var encryptPassword = Md5.Encrypt(param.User.Password);

            //檢查使用者的密碼
            if (string.IsNullOrEmpty(userDetail.EncryptPassword) || !userDetail.EncryptPassword.Equals(encryptPassword))
            {
                return(false);
            }
            //如果是最高管理者需要再驗證IP
            if (userDetail.IsAdministrator)
            {
                if (!VerifyConnectSourceIp(param.RemoteIp))
                {
                    return(false);
                }
            }
            var principal = new ManagerPrincipal(userDetail.Account);

            //HttpContext.Current.User = principal;
            //Identity = HttpContext.Current.User.Identity as ManagerIdentity;
            //註冊Cookies
            //AddCookie(userDetail);
            AddCookie(principal);
            CacheProvider.Insert(userDetail.Account, principal);
            return(true);
        }
        /// <summary>
        /// 從 Cookie 或快取中取得使用者資料
        /// </summary>
        /// <returns></returns>
        public static IPrincipal GetUser()
        {
            if (!Cookie.IsExist(HttpContext.Current.Request.Url.Authority))
            {
                return(null);
            }

            if (HttpContext.Current.User != null && HttpContext.Current.User.Identity.IsAuthenticated)
            {
                //return CacheProvider.Get<IPrincipal>(HttpContext.Current.User.Identity.Name);
                //重設過期時間
                AddCookie(HttpContext.Current.User);
                CacheProvider.Insert(HttpContext.Current.User.Identity.Name, HttpContext.Current.User);
                return(HttpContext.Current.User);
            }
            try
            {
                var infoString = AzDG.Decrypt(Cookie.Get(HttpContext.Current.Request.Url.Authority));
                var info       = infoString.Split(new[] { CookieSplittor }, StringSplitOptions.None);
                //20131203 加入快取機制
                var principal = CacheProvider.Get <IPrincipal>(info[1]);
                if (principal != null)
                {
                    AddCookie(principal);
                    CacheProvider.Insert(principal.Identity.Name, principal);
                    return(principal);
                }
                principal = new ManagerPrincipal(info[1]);
                //重設過期時間
                AddCookie(principal);
                CacheProvider.Insert(info[1], principal);
                return(principal);
            }
            catch (Exception ex)
            {
                return(null);
            }
        }