Ejemplo n.º 1
0
 public WebNavigator()
 {
     cookie        = new CookieContainer();
     usr           = new UserInfo();
     connected     = false;
     cookieManager = new WebCookie();
 }
Ejemplo n.º 2
0
        /// <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);
        }
Ejemplo n.º 3
0
 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());
 }
Ejemplo n.º 4
0
        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);
        }
Ejemplo n.º 5
0
        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);
        }
Ejemplo n.º 6
0
        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);
        }
Ejemplo n.º 7
0
        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);
        }
Ejemplo n.º 8
0
        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);
        }
Ejemplo n.º 9
0
        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);
        }
Ejemplo n.º 10
0
        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());
        }
Ejemplo n.º 11
0
        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());
        }
Ejemplo n.º 12
0
        /// <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);
        }
Ejemplo n.º 13
0
        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());
        }
Ejemplo n.º 14
0
        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());
        }
Ejemplo n.º 15
0
        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());
        }
Ejemplo n.º 16
0
        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());
        }
Ejemplo n.º 17
0
        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());
        }
Ejemplo n.º 18
0
        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());
        }
Ejemplo n.º 19
0
        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());
        }
Ejemplo n.º 20
0
        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);
        }
Ejemplo n.º 22
0
        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));
            }
        }
Ejemplo n.º 23
0
 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;
        }