public static Dictionary <string, string> GetRoomContexts(string userCookieValue) { try { if (userCookieValue != "") { SimpleCrypto cryptographer = new SimpleCrypto(); userCookieValue = cryptographer.TDesDecrypt(userCookieValue); Dictionary <string, string> userContexts = new Dictionary <string, string>(); if (userCookieValue != null && userCookieValue != "") { string[] userContext = userCookieValue.Split('&'); foreach (string con in userContext) { string roomId = con.Split('=')[0]; string roomContext = con.Split('=')[1]; userContexts.Add(roomId, roomContext); } return(userContexts); } } return(new Dictionary <string, string>()); } catch (System.Exception) { return(null); } }
public static void SetCurrentContext(string roomId, string newUserContext) { Dictionary <string, string> userContexts = GetRoomContexts(); string currentRoomContext = GetCurrentRoomContext(roomId, Session.GetCurrentUserId(), null); if (userContexts != null) { if (currentRoomContext != null) { if (roomId != null && roomId != "") { if (userContexts.ContainsKey(roomId)) { userContexts.Remove(roomId); } } } } else { userContexts = new Dictionary <string, string>(); } userContexts.Add(roomId, newUserContext); string cookieValue = ""; string delimiter = ""; foreach (KeyValuePair <string, string> userCon in userContexts) { cookieValue += delimiter + userCon.Key + "=" + userCon.Value; delimiter = "&"; } SimpleCrypto cryptographer = new SimpleCrypto(); cookieValue = cryptographer.TDesEncrypt(cookieValue); HttpCookie cookie = new HttpCookie(contextCookieName, cookieValue); cookie.Domain = _domain; cookie.Value = cookieValue; HttpCookie existsCookie = HttpContext.Current.Request.Cookies.Get(contextCookieName); if (existsCookie == null) { HttpContext.Current.Response.Cookies.Add(cookie); HttpContext.Current.Request.Cookies.Add(cookie); } else { HttpContext.Current.Response.Cookies.Set(cookie); HttpContext.Current.Request.Cookies.Set(cookie); } }
public void SetAddCookieUserOnRampTracking(string name, string value) { string cookieValue = ""; if (name == null) { cookieValue = value; } else if (name.Length > 0) { cookieValue = "||" + name + "-->" + value; } else { cookieValue = value; } HttpCookie existsCookie = HttpContext.Current.Request.Cookies.Get("onRampTracking"); SimpleCrypto cryptographer = new SimpleCrypto(); if (existsCookie != null) { string currentCookie = cryptographer.TDesDecrypt(existsCookie.Value).Trim(); if (currentCookie.Contains(cookieValue.Trim())) { cookieValue = currentCookie; } else { cookieValue = currentCookie + "||" + cookieValue; } } cookieValue = cryptographer.TDesEncrypt(cookieValue); HttpCookie newOnRampTrackingCookie = new HttpCookie("onRampTracking", cookieValue); newOnRampTrackingCookie.Domain = ConfigurationManager.AppSettings["domain"]; if (existsCookie == null) { HttpContext.Current.Response.Cookies.Add(newOnRampTrackingCookie); HttpContext.Current.Request.Cookies.Add(newOnRampTrackingCookie); } else { HttpContext.Current.Response.Cookies.Set(newOnRampTrackingCookie); HttpContext.Current.Request.Cookies.Set(newOnRampTrackingCookie); } }
//GET METHOD public void AddParam(string paramName, string paramValue) { string tempValue = paramValue; if (mEncrypted == true) { SimpleCrypto cryptographer = new SimpleCrypto(); tempValue = cryptographer.TDesEncrypt(tempValue); } if (mStringParams.ContainsKey(paramName)) { mStringParams.Remove(paramName); } mStringParams.Add(paramName, tempValue); }
/// <summary> /// Returns the current usrs encrypted payment information needed to start a /// Money transaction. The payment information needed to start a Money transaction is /// the combination of the sessionId GUID and the hangoutUserId /// </summary> /// <param name="response">The response from the Payment Command</param> /// <param name="noun">The noun for the payment command</param> /// <param name="verb">The verb for the payment command</param> /// <param name="sessionId">The sessionId GUID for the current users session</param> /// <returns></returns> public XmlDocument GetPaymentItemSecurePaymentInfoEncrypted(XmlDocument response, string noun, string verb, Guid sessionId) { if ((noun == "HangoutUsers") && (verb == "SecurePaymentInfo")) { ServerAccount account = mServerStateMachine.SessionManager.GetServerAccountFromSessionId(sessionId); string hangoutUserId = account.AccountId.ToString(); string secureInfo = String.Format("{0}&{1}", sessionId, hangoutUserId); SimpleCrypto crypt = new SimpleCrypto(); XmlNode newNode = response.CreateNode("element", "SecureInfo", ""); newNode.InnerText = crypt.TDesEncrypt(secureInfo); XmlNode xmlDocNode = response.SelectSingleNode("/Response"); xmlDocNode.AppendChild(newNode); } return(response); }
public static UserId GetCurrentUser(string userCookieValue) { try { if (userCookieValue != null) { if (userCookieValue != "") { SimpleCrypto cryptographer = new SimpleCrypto(); userCookieValue = cryptographer.TDesDecrypt(userCookieValue); int id = System.Convert.ToInt32(userCookieValue.Substring(0, userCookieValue.IndexOf(cookieToken))); DateTime expiration = DateTime.Parse(userCookieValue.Substring(userCookieValue.IndexOf(cookieToken) + 2)); if (expiration < DateTime.Now || id == 0) { return(null); } else { return(new UserId(id)); } } else { return(null); } } else { return(null); } } catch (System.Exception) { return(null); } }
public static void SetCurrentUserId(int val) { string cookieValue = val + cookieToken + DateTime.Now.AddHours(1); SimpleCrypto cryptographer = new SimpleCrypto(); cookieValue = cryptographer.TDesEncrypt(cookieValue); HttpCookie cookie = new HttpCookie(cookieName, cookieValue); cookie.Domain = _domain; cookie.Value = cookieValue; HttpCookie existsCookie = HttpContext.Current.Request.Cookies.Get(cookieName); if (existsCookie == null) { HttpContext.Current.Response.Cookies.Add(cookie); HttpContext.Current.Request.Cookies.Add(cookie); } else { HttpContext.Current.Response.Cookies.Set(cookie); HttpContext.Current.Request.Cookies.Set(cookie); } }