public static void savePersistentCookie(PersistentCookie c) { String json = JsonConvert.SerializeObject(c, new Newtonsoft.Json.Converters.IsoDateTimeConverter()); ICryptHelper cryptUtil = CryptFactory.GetCryptHelper(ConfigurationManager.AppSettings["Encryption"]); HttpCookie cookie = new HttpCookie(PERSISTENT_COOKIE_KEY); cookie.Value = cryptUtil.Encrypt(json); cookie.Expires = DateTime.Now.AddDays(500); HttpContext.Current.Response.Cookies.Add(cookie); }
/// <summary> /// The user clicked the Login button, so process it here. /// </summary> private void processLogin() { if (validForm()) { ICryptHelper cryptUtil = CryptFactory.GetCryptHelper(ConfigurationManager.AppSettings["Encryption"]); Session[Config.SESSION_AWSKEY] = cryptUtil.Encrypt(this.awsKey); Session[Config.SESSION_AWSSECRET] = cryptUtil.Encrypt(this.awsSecret); // remember the login credentials in an encrypted cookie. if (this.rememberLogin == "1") { PersistentCookie persistentCookie; if (CookieUtils.hasPersistentCookie()) { persistentCookie = CookieUtils.getPersistentCookie(); } else // cookie not found, create one. { persistentCookie = new PersistentCookie(); } persistentCookie.awsKey = this.awsKey; persistentCookie.awsSecret = this.awsSecret; CookieUtils.savePersistentCookie(persistentCookie); } else { // checkbox not selected, remove the cookie. CookieUtils.deletePersistentCookie(); } goToURL(); } }