Ejemplo n.º 1
0
        public string Get(string key)
        {
            string value = GetValue(key);

            if (value != null)
            {
                return(CryptographyHelper.Decrypt(value));
            }

            return(null);
        }
Ejemplo n.º 2
0
 public void RememberMe(string userName, string password)
 {
     if (_response != null)
     {
         string data = userName + "," + password;
         data = CryptographyHelper.Encrypt(data);
         HttpCookie userAuthCookie = new HttpCookie(Constants.CommonConstants.RememberMeCookieName, data);
         userAuthCookie.Expires = DateTime.UtcNow.AddYears(1);
         HttpContext.Current.Response.Cookies.Add(userAuthCookie);
         _response.Cookies.Add(userAuthCookie);
     }
 }
Ejemplo n.º 3
0
        private string GetValue(string key)
        {
            HttpCookie cookie = GetCookie(CryptographyHelper.Encrypt(BuildFullKey(key)));

            if (cookie == null)
            {
                return(null);
            }

            if (string.IsNullOrEmpty(cookie.Value))
            {
                return(null);
            }

            return(HttpUtility.UrlDecode(cookie.Value));
        }
Ejemplo n.º 4
0
 public void GetUserDataFromRememberMeCookie(ref string userName, ref string password)
 {
     if (_request != null)
     {
         HttpCookie userDataCookie = _request.Cookies.Get(Constants.CommonConstants.RememberMeCookieName);
         if (userDataCookie != null)
         {
             string userData = userDataCookie.Value;
             if (!string.IsNullOrEmpty(userData))
             {
                 userData = CryptographyHelper.Decrypt(userData);
                 string[] values = userData.Split(',').ToArray();
                 if (values != null && values.Length >= 2)
                 {
                     userName = values[0];
                     password = values[1];
                 }
             }
         }
     }
 }
Ejemplo n.º 5
0
 public string GetUserDataFromLoginCookie()
 {
     if (_response != null)
     {
         if (HttpContext.Current.User != null)
         {
             if (HttpContext.Current.User.Identity.IsAuthenticated)
             {
                 if (HttpContext.Current.User.Identity is FormsIdentity)
                 {
                     FormsIdentity             formIdentity   = (FormsIdentity)HttpContext.Current.User.Identity;
                     FormsAuthenticationTicket userAuthTicket = formIdentity.Ticket;
                     if (!string.IsNullOrEmpty(userAuthTicket.UserData))
                     {
                         return(CryptographyHelper.Decrypt(userAuthTicket.UserData));
                     }
                 }
             }
         }
     }
     return(string.Empty);
 }
Ejemplo n.º 6
0
 public void Set(string key,
                 string value)
 {
     SetValue(CryptographyHelper.Encrypt(BuildFullKey(key)), CryptographyHelper.Encrypt(value));
 }
Ejemplo n.º 7
0
 public void Set(string key,
                 string value,
                 DateTime expire)
 {
     SetValue(CryptographyHelper.Encrypt(BuildFullKey(key)), CryptographyHelper.Encrypt(value), expire);
 }