public WebNavigator() { cookie = new CookieContainer(); usr = new UserInfo(); connected = false; cookieManager = new WebCookie(); }
/// <summary> /// Adds the given cookie /// </summary> /// <param name="name"></param> /// <param name="value"></param> public void Add(string name, string value) { WebCookie c = new WebCookie(); c.Name = name; c.Value = value; m_InnerList.Add(c); }
public ActionResult Login(string pwd, string account) { if (accessDb.checkLogin(account, pwd)) { WebCookie cookie = new WebCookie(); cookie.CreateUserAuthCookie(account.DESEncrypt()); Response.Redirect("/Home/Chat"); } return(View()); }
public void GoogleGaps() { var cookie = WebCookie.FromString("GAPS=1:A1aaaaAaAAa1aaAaAaaAAAaaa1a11a:aaaAaAaAa-aaaA1-;Path=/;Expires=Thu, 17-Apr-2014 02:12:29 GMT;Secure;HttpOnly"); Assert.AreEqual("GAPS", cookie.Key); Assert.AreEqual("1:A1aaaaAaAAa1aaAaAaaAAAaaa1a11a:aaaAaAaAa-aaaA1-", cookie.Value); Assert.AreEqual("/", cookie.Path); Assert.AreEqual(new DateTime(2014, 4, 17), cookie.Expires.Value.Date); Assert.IsTrue(cookie.IsSecure); Assert.IsTrue(cookie.IsHttpOnly); }
public void CookieWithNonAsciiInValue() { var cookie = WebCookie.FromString("farbe=weiß"); Assert.AreEqual("farbe", cookie.Key); Assert.AreEqual("weiß", cookie.Value); Assert.AreEqual(null, cookie.Path); Assert.IsFalse(cookie.Expires.HasValue); Assert.IsFalse(cookie.IsSecure); Assert.IsFalse(cookie.IsHttpOnly); }
public void CookieWithManyEqualSigns() { var cookie = WebCookie.FromString("queryPref=b=c&d=e; Path=/f=g; Expires=Thu, 17 Apr 2014 02:12:29 GMT; HttpOnly"); Assert.AreEqual("queryPref", cookie.Key); Assert.AreEqual("b=c&d=e", cookie.Value); Assert.AreEqual("/f=g", cookie.Path); Assert.AreEqual(new DateTime(2014, 4, 17), cookie.Expires.Value.Date); Assert.IsFalse(cookie.IsSecure); Assert.IsTrue(cookie.IsHttpOnly); }
public void CookieWithWeirdFormat() { var cookie = WebCookie.FromString("=foo=bar", loose: true); Assert.AreEqual("foo", cookie.Key); Assert.AreEqual("bar", cookie.Value); Assert.AreEqual(null, cookie.Path); Assert.IsFalse(cookie.Expires.HasValue); Assert.IsFalse(cookie.IsSecure); Assert.IsFalse(cookie.IsHttpOnly); }
public void CookieWithNonExistingKey() { var cookie = WebCookie.FromString("foo", loose: true); Assert.AreEqual("", cookie.Key); Assert.AreEqual("foo", cookie.Value); Assert.AreEqual(null, cookie.Path); Assert.IsFalse(cookie.Expires.HasValue); Assert.IsFalse(cookie.IsSecure); Assert.IsFalse(cookie.IsHttpOnly); }
public void CookieWithQuotesSpacesInTheValue() { var cookie = WebCookie.FromString("a=\"one two three\""); Assert.AreEqual("a", cookie.Key); Assert.AreEqual("\"one two three\"", cookie.Value); Assert.AreEqual(null, cookie.Path); Assert.IsFalse(cookie.Expires.HasValue); Assert.IsFalse(cookie.IsSecure); Assert.IsFalse(cookie.IsHttpOnly); }
public void ExpiringCookie() { var cookie = WebCookie.FromString("a=bcd; Expires=Tue, 18 Oct 2011 07:05:03 GMT"); Assert.AreEqual("a", cookie.Key); Assert.AreEqual("bcd", cookie.Value); Assert.IsTrue(cookie.Validate()); Assert.AreEqual(null, cookie.Path); Assert.AreEqual(null, cookie.Domain); Assert.AreEqual(new DateTime(2011, 10, 18), cookie.Expires.Value.Date); Assert.AreEqual(0, cookie.Extensions.Count()); }
public void SimpleCookie() { var cookie = WebCookie.FromString("a=bcd"); Assert.AreEqual("a", cookie.Key); Assert.AreEqual("bcd", cookie.Value); Assert.IsTrue(cookie.Validate()); Assert.AreEqual(null, cookie.Path); Assert.AreEqual(null, cookie.Domain); Assert.IsFalse(cookie.Expires.HasValue); Assert.AreEqual(0, cookie.Extensions.Count()); }
/// <summary> /// Executes this tag. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> protected override void DoExecute(IMansionContext context) { // create the cookie var cookie = new WebCookie { Name = GetRequiredAttribute<string>(context, "name"), HttpOnly = GetAttribute(context, "httpOnly", true), Expires = GetAttribute(context, "expires", DateTime.Today.AddDays(30)), Value = GetRequiredAttribute<string>(context, "value") }; // set the cookie context.SetCookie(cookie); }
public void ExpiringCookieWithPath() { var cookie = WebCookie.FromString("a=\"xyzzy!\"; Expires=Tue, 18 Oct 2011 07:05:03 GMT; Path=/aBc"); Assert.AreEqual("a", cookie.Key); Assert.AreEqual("\"xyzzy!\"", cookie.Value); Assert.AreEqual("/aBc", cookie.Path); Assert.AreEqual(null, cookie.Domain); Assert.IsFalse(cookie.IsSecure); Assert.IsFalse(cookie.IsHttpOnly); Assert.AreEqual(new DateTime(2011, 10, 18), cookie.Expires.Value.Date); Assert.AreEqual(0, cookie.Extensions.Count()); }
public void HttpOnlyCookieWithValue() { var cookie = WebCookie.FromString("a=b; HttpOnly=xyxz"); Assert.AreEqual("a", cookie.Key); Assert.AreEqual("b", cookie.Value); Assert.AreEqual(null, cookie.Path); Assert.AreEqual(null, cookie.Domain); Assert.IsFalse(cookie.IsSecure); Assert.IsTrue(cookie.IsHttpOnly); Assert.IsFalse(cookie.Expires.HasValue); Assert.AreEqual(0, cookie.Extensions.Count()); }
public void CookieWithInvalidExpirationDate() { var cookie = WebCookie.FromString("a=b; Expires=xyzzy"); Assert.AreEqual("a", cookie.Key); Assert.AreEqual("b", cookie.Value); Assert.AreEqual(null, cookie.Path); Assert.AreEqual(null, cookie.Domain); Assert.IsFalse(cookie.IsSecure); Assert.IsFalse(cookie.IsHttpOnly); Assert.IsFalse(cookie.Expires.HasValue); Assert.AreEqual(0, cookie.Extensions.Count()); }
public void CookieWithTrailingSemicolons() { var cookie = WebCookie.FromString("a=b;;;;"); Assert.AreEqual("a", cookie.Key); Assert.AreEqual("b", cookie.Value); Assert.AreEqual(null, cookie.Path); Assert.AreEqual(null, cookie.Domain); Assert.IsFalse(cookie.IsSecure); Assert.IsFalse(cookie.IsHttpOnly); Assert.IsFalse(cookie.Expires.HasValue); Assert.AreEqual(0, cookie.Extensions.Count()); }
public void CookieWitUppercaseDomain() { var cookie = WebCookie.FromString("a=b; domain=EXAMPLE.COM"); Assert.AreEqual("a", cookie.Key); Assert.AreEqual("b", cookie.Value); Assert.AreEqual(null, cookie.Path); Assert.AreEqual("example.com", cookie.Domain); Assert.IsFalse(cookie.MaxAge.HasValue); Assert.IsFalse(cookie.IsSecure); Assert.IsFalse(cookie.IsHttpOnly); Assert.IsFalse(cookie.Expires.HasValue); Assert.AreEqual(0, cookie.Extensions.Count()); }
public void CookieWithNegativeMaxAge() { var cookie = WebCookie.FromString("a=b; Max-Age=-1"); Assert.AreEqual("a", cookie.Key); Assert.AreEqual("b", cookie.Value); Assert.AreEqual(null, cookie.Path); Assert.AreEqual(null, cookie.Domain); Assert.AreEqual(-1, cookie.MaxAge.Value); Assert.IsFalse(cookie.IsSecure); Assert.IsFalse(cookie.IsHttpOnly); Assert.IsFalse(cookie.Expires.HasValue); Assert.AreEqual(0, cookie.Extensions.Count()); }
public void CompleteCookie() { var cookie = WebCookie.FromString("abc=\"xyzzy!\"; Expires=Tue, 18 Oct 2011 07:05:03 GMT; Path=/aBc; Domain=example.com; Secure; HTTPOnly; Max-Age=1234; Foo=Bar; Baz"); Assert.AreEqual("abc", cookie.Key); Assert.AreEqual("\"xyzzy!\"", cookie.Value); Assert.AreEqual("/aBc", cookie.Path); Assert.AreEqual("example.com", cookie.Domain); Assert.IsTrue(cookie.IsSecure); Assert.IsTrue(cookie.IsHttpOnly); Assert.AreEqual(1234, cookie.MaxAge.Value); Assert.AreEqual(new DateTime(2011, 10, 18), cookie.Expires.Value.Date); Assert.AreEqual("Foo=Bar", cookie.Extensions.Skip(0).First()); Assert.AreEqual("Baz", cookie.Extensions.Skip(1).First()); }
private IEnumerable <WebCookie> GetWebCookies(string webview_x5File) { var localWebCookie = new List <WebCookie>(); if (string.IsNullOrEmpty(webview_x5File)) { return(localWebCookie); } var copyFiles = SqliteRecoveryHelper.DataRecovery(webview_x5File, @"chalib\Andorid_QQBrowse_V5.1.0.780\webview_x5.db.charactor", "cookies"); var context = new SqliteContext(copyFiles); try { var objList = context.FindByName("cookies"); if (objList != null) { foreach (dynamic source in objList) { var cookie = new WebCookie(); cookie.DataState = DynamicConvert.ToEnumByValue(source.XLY_DataType, EnumDataState.Normal); cookie.Name = DynamicConvert.ToSafeString(source.name); cookie.Value = DynamicConvert.ToSafeString(source.value); cookie.Domain = DynamicConvert.ToSafeString(source.domain); cookie.ExpresTime = DynamicConvert.ToSafeDateTime(source.expires); localWebCookie.Add(cookie); } } } catch { } return(localWebCookie); }
private IEnumerable <WebCookie> GetWebCookies(string webviewCookiesChromiumFile) { //data/data/com.android.browser/databases/webviewCookiesChromium.db var localWebCookie = new List <WebCookie>(); if (string.IsNullOrEmpty(webviewCookiesChromiumFile)) { return(localWebCookie); } string copyfiles = SqliteRecoveryHelper.DataRecovery(webviewCookiesChromiumFile, @"chalib\Android_LocalBrowse\webviewCookiesChromium.charactor", "cookies"); var context = new SqliteContext(copyfiles); try { var objList = context.FindByName("cookies"); if (objList != null) { foreach (dynamic source in objList) { var cookie = new WebCookie(); cookie.DataState = DynamicConvert.ToEnumByValue(source.XLY_DataType, EnumDataState.Normal); cookie.Name = DynamicConvert.ToSafeString(source.name); cookie.Value = DynamicConvert.ToSafeString(source.value); cookie.Domain = DynamicConvert.ToSafeString(source.host_key); cookie.ExpresTime = DynamicConvert.ToSafeDateTime(source.expires_utc); localWebCookie.Add(cookie); } } } catch { } return(localWebCookie); }
public ActionResult Login(string UserName, string UserPwd) { Model.Account ac = new BLL.Account().Login(UserName, Common.Security.Md5Hash(UserPwd), "0,1"); if (ac != null) { WebCookie.AddCookie(ac.Id.ToString(), ac.AccountName, ac.AType.ToString(), ac.CompanyId.ToString());//存cookie var result = new { success = 0, msg = "登录成功" }; return(Json(result)); } else { var result = new { success = 1, msg = "登录失败" }; return(Json(result)); } }
public ActionResult LoginOut() { //清除登录 WebCookie.RemoveCookie(); return(Redirect(Url.Action("login", "main"))); }
/// <summary> /// Transfers the given <paramref name="cookie"/> to the <paramref name="httpResponse"/>. /// </summary> /// <param name="cookie">The <see cref="WebCookie"/>.</param> /// <param name="httpResponse">The <see cref="HttpResponseBase"/>.</param> /// <exception cref="ArgumentNullException">Thrown if one of the parameters is null.</exception> public static void TransferCookie(WebCookie cookie, HttpResponseBase httpResponse) { // validate arguments if (cookie == null) throw new ArgumentNullException("cookie"); if (httpResponse == null) throw new ArgumentNullException("httpResponse"); // create the http cookie var httpCookie = new HttpCookie(cookie.Name, cookie.Value) { Secure = cookie.Secure, HttpOnly = cookie.HttpOnly }; // check for domain if (!string.IsNullOrEmpty(cookie.Domain)) httpCookie.Domain = cookie.Domain; // check expires if (cookie.Expires.HasValue) httpCookie.Expires = cookie.Expires.Value; // add the cookie to the response httpResponse.Cookies.Add(httpCookie); }
/// <summary> /// Authenticates the user. /// </summary> /// <param name="context">The <see cref="IMansionContext"/>.</param> /// <param name="authenicationProvider">The authentication provider which to use.</param> /// <param name="parameters">The parameters used for authentication.</param> /// <returns>Returns the <see cref="AuthenticationResult"/>.</returns> protected override AuthenticationResult DoAuthenticate(IMansionContext context, AuthenticationProvider authenicationProvider, IPropertyBag parameters) { // authenticate var result = authenicationProvider.Authenticate(context, parameters); if (!result.WasSuccesful) return result; var user = result.UserState; // get the web request context var webContext = context.Cast<IMansionWebContext>(); // check session if (!webContext.Session.IsWritable) throw new InvalidOperationException("Could not authenticate user because the session is not writeable"); // store this user in the session webContext.Session[GetRevivalCookieName(context)] = user; // check if the authentication provider support user revival and the rememberMe flag was set var revivalCookieName = GetRevivalCookieName(context); if (authenicationProvider.SupportsRevival && parameters.Get(context, "allowRevival", false)) { // get the revival data for this user var revivalData = authenicationProvider.GetRevivalProperties(context, user, parameters); if (revivalData != null) { // add additional revival properties revivalData.Set("authenticationProviderName", authenicationProvider.Name); revivalData.Set("userSignature", GetUserSignatureHash(webContext)); // encrypt it var serializedRevivalData = conversionService.Convert<byte[]>(context, revivalData); var encryptedRevivalData = encryptionService.Encrypt(context, cookieSalt, serializedRevivalData); var revivalDataString = conversionService.Convert<string>(context, encryptedRevivalData); // store it in a cookie var revivalCookie = new WebCookie { Name = revivalCookieName, Value = revivalDataString, Expires = DateTime.Now.AddDays(14), HttpOnly = true }; context.SetCookie(revivalCookie); } } else context.DeleteCookie(revivalCookieName); // authentication was successful return result; }