示例#1
0
 public LoginEventArgs(SiteLoginDetails loginDetails)
 {
     this.LoginDetails = loginDetails;
 }
示例#2
0
        public override void LoginUser(string username, string password)
        {
            AsyncHelper.Run(() =>
            {
                byte[] rawData, hash, hashUtf8 = null;
                string data = null;
                string url = this.BaseUrl + this.LoginPath;
                var details = new SiteLoginDetails(false, username, password);
                int check = 0;
                int parse = -1;

                using (var md5 = new System.Security.Cryptography.MD5CryptoServiceProvider())
                {
                    hash = md5.ComputeHash(Encoding.ASCII.GetBytes(password));
                    hashUtf8 = md5.ComputeHash(Encoding.UTF8.GetBytes(password));
                }

                data = String.Format(
                    Res.vBulletin_400_Login,
                    details.GetUrlSafeUsername(this.SiteEncoding),
                    details.GetUrlSafePassword(this.SiteEncoding),
                    BitConverter.ToString(hash).Replace("-", "").ToLower(),
                    BitConverter.ToString(hashUtf8).Replace("-", "").ToLower()
                );

                rawData = this.SiteEncoding.GetBytes(data);

                this.LogoutUser();

                HttpWebRequest req = Http.Prepare(url);
                Stream stream;

                req.Method = "POST";
                req.Referer = url;
                req.ContentType = Res.FormContentType;
                req.ContentLength = rawData.Length;

                stream = req.GetRequestStream();
                stream.Write(rawData, 0, rawData.Length);
                stream.Close();

                HttpResult result = this.AllowRedirects ? Http.HandleRedirects(Http.FastRequest(req), true) : Http.FastRequest(req);

                // Did the request fail?
                if (result.HasError)
                {
                    ErrorLog.LogException(result.Error);
                    this.User = details;
                    this.OnLogin(this, new LoginEventArgs(details));
                    return;
                }

                if (result.HasResponse) this.SiteEncoding = Encoding.GetEncoding(result.Response.CharacterSet);

                // Check if we did login
                foreach (Cookie c in Http.GetDomainCookies(req.RequestUri))
                {
                    if (c.Name.EndsWith("userid"))
                    {
                        if (c.Value.Length > 0 && int.TryParse(c.Value, out parse) && parse > 0) check++;
                    }
                    else if (c.Name.EndsWith("password"))
                    {
                        if (c.Value.Length > 1) check++;
                    }
                }

                if (check > 1)
                {
                    details.IsLoggedIn = true;

                    foreach (var c in Http.GetDomainCookies(req.RequestUri))
                    {
                        details.Cookies.Add(c);
                    }
                }
                else
                {
                    var error = new Exception(String.Format(
                        "Login check failed for '{0}'.\r\nCheck count: {1}.",
                        this.BaseUrl,
                        check
                    ));

                    ErrorLog.LogException(error);
                }

                this.User = details;
                this.OnLogin(this, new LoginEventArgs(details));
                return;
            });
        }
示例#3
0
        public override void LoginUser(string username, string password)
        {
            AsyncHelper.Run(() =>
            {
                string url = this.BaseUrl + this.LoginPath;
                var details = new SiteLoginDetails(false, username, password);
                var data = String.Format(
                    Res.IPBoard_300_Login,
                    details.GetUrlSafeUsername(this.SiteEncoding),
                    details.GetUrlSafePassword(this.SiteEncoding)
                );
                data = "referer=" + HttpUtility.UrlEncode(this.BaseUrl + "/index.php?", this.SiteEncoding) + "&" + data;
                byte[] rawData = this.SiteEncoding.GetBytes(data);
                int check = 0;
                int parse = -1;

                this.LogoutUser();

                HttpWebRequest req = Http.Prepare(url);
                Stream stream;

                req.Method = "POST";
                req.Referer = url;
                req.ContentType = Res.FormContentType;
                req.ContentLength = rawData.Length;

                stream = req.GetRequestStream();
                stream.Write(rawData, 0, rawData.Length);
                stream.Close();

                HttpResult result = this.AllowRedirects ? Http.HandleRedirects(Http.FastRequest(req), true) : Http.FastRequest(req);

                // Did the request fail?
                if (result.HasError || Http.SessionCookies.Count < 2)
                {
                    ErrorLog.LogException(result.Error);
                    this.User = details;
                    this.OnLogin(this, new LoginEventArgs(details));
                    return;
                }

                if (result.HasResponse) this.SiteEncoding = Encoding.GetEncoding(result.Response.CharacterSet);

                // Check if we did login
                foreach (Cookie c in Http.GetDomainCookies(req.RequestUri))
                {
                    if (c.Name.EndsWith("member_id"))
                    {
                        if (c.Value.Length > 0 && int.TryParse(c.Value, out parse) && parse > 0) check++;
                    }
                    else if (c.Name.EndsWith("pass_hash"))
                    {
                        if (c.Value.Length > 1) check++;
                    }
                }

                if (check > 1)
                {
                    details.IsLoggedIn = true;

                    foreach (var c in Http.GetDomainCookies(req.RequestUri))
                    {
                        details.Cookies.Add(c);
                    }
                }
                else
                {
                    var error = new Exception(String.Format(
                        "Login check failed for '{0}'.\r\nCheck count: {1}.",
                        this.BaseUrl,
                        check
                    ));

                    ErrorLog.LogException(error);
                }

                this.User = details;
                this.OnLogin(this, new LoginEventArgs(details));
                return;
            });
        }
示例#4
0
 public LoginEventArgs(SiteLoginDetails loginDetails)
 {
     this.LoginDetails = loginDetails;
 }