private void LoginForm_FormClosing(object sender, FormClosingEventArgs e) { loginResponse = null; updateGuiFromResponse(); messageLabel.Text = string.Empty; messageLabel.Visible = false; }
/// <summary> /// /// </summary> public JSON.Report.SiteList.ReportResponse GetSiteList() { try { if (this.loginResponse == null || loginResponse.ReturnCode != 0) { // 重新登录 this.loginResponse = this.login.DoLogin(); } ReportRequest data = new ReportRequest(); data.Header.AccountType = "1"; data.Header.Password = this.loginResponse.ST; data.Header.Token = this.login.Token; data.Header.UserName = this.login.UserName; string value = HttpManager.RequestReport(Report.URL + "/getSiteList", this.loginResponse.UCID, data); JSON.Report.SiteList.ReportResponse response = JsonConvert.DeserializeObject <JSON.Report.SiteList.ReportResponse>(value); return(response); } catch { throw; } finally { if (this.loginResponse != null || loginResponse.ReturnCode == 0) { // 登出 this.login.DoLogout(this.loginResponse.UCID, this.loginResponse.ST); } } }
internal static SkadiLoginError Create(DoLoginResponse doLoginResponse) { SkadiLoginError skadiLoginError = new SkadiLoginError(); if (doLoginResponse.CaptchaNeeded) { skadiLoginError.CaptchaNeeded = doLoginResponse.CaptchaNeeded; skadiLoginError.CaptchaGid = doLoginResponse.CaptchaGid; skadiLoginError.Message = doLoginResponse.Message; skadiLoginError.Type = ErrorType.CaptchaNeeded; } else if (doLoginResponse.RequiresTwoFactor) { skadiLoginError.CaptchaNeeded = doLoginResponse.CaptchaNeeded; skadiLoginError.CaptchaGid = doLoginResponse.CaptchaGid; skadiLoginError.Message = doLoginResponse.Message; skadiLoginError.Type = ErrorType.TwoFactor; } else if (doLoginResponse.Message == "Incorrect login.") { skadiLoginError.CaptchaNeeded = doLoginResponse.CaptchaNeeded; skadiLoginError.CaptchaGid = doLoginResponse.CaptchaGid; skadiLoginError.Message = doLoginResponse.Message; skadiLoginError.Type = ErrorType.IncorrectLogin; } return(skadiLoginError); }
public void CheckNotSuccessful() { DoLoginResponse doLoginResponse = new DoLoginResponse(); doLoginResponse.Success = false; doLoginResponse.LoginComplete = true; Assert.False(DoLoginResponseValidator.IsValid(doLoginResponse)); }
public void CheckValid() { DoLoginResponse doLoginResponse = new DoLoginResponse(); doLoginResponse.Success = true; doLoginResponse.LoginComplete = true; Assert.True(DoLoginResponseValidator.IsValid(doLoginResponse)); }
private void Transfer(DoLoginResponse doLoginResponse) { var content = PostDataFactory.CreateTransferData(doLoginResponse); _requestFactory.Create(HttpMethod.POST, Uris.HelpSteampoweredSecureBase, HelpSteampoweredEndpoints.TransferLogin, Accept.Html, HttpHeaderValues.AcceptLanguageTwo, true, true, true, false, true, content); }
public DoLoginResponse DoLogin() { this.header.FunctionName = "doLogin"; this.request = new DoLoginRequest(); this.header.Request = request; (this.request as DoLoginRequest).Password = this.password; DoLoginResponse value = this.Request <DoLoginResponse>(); return(value); }
public void CaptchaNeeded() { DoLoginResponse doLoginResponse = new DoLoginResponse(); doLoginResponse.CaptchaNeeded = true; doLoginResponse.CaptchaGid = 677901403761260; doLoginResponse.Message = ""; doLoginResponse.RequiresTwoFactor = false; var skadiLoginError = SkadiLoginErrorFactory.Create(doLoginResponse); Assert.Equal(ErrorType.CaptchaNeeded, skadiLoginError.Type); }
public void IncorrectLogin() { DoLoginResponse doLoginResponse = new DoLoginResponse(); doLoginResponse.CaptchaNeeded = false; doLoginResponse.CaptchaGid = -1; doLoginResponse.Message = "Incorrect login."; doLoginResponse.RequiresTwoFactor = false; var skadiLoginError = SkadiLoginErrorFactory.Create(doLoginResponse); Assert.Equal(ErrorType.IncorrectLogin, skadiLoginError.Type); }
internal static List <KeyValuePair <string, string> > CreateTransferData(DoLoginResponse doLoginResponse) { var content = new List <KeyValuePair <string, string> > { new KeyValuePair <string, string>(PostParameters.Auth, doLoginResponse.TransferParameters.Auth), new KeyValuePair <string, string>(PostParameters.RememberLogin, doLoginResponse.TransferParameters.RememberLogin.ToString()), new KeyValuePair <string, string>(PostParameters.SteamId, doLoginResponse.TransferParameters.SteamId), new KeyValuePair <string, string>(PostParameters.Token, doLoginResponse.TransferParameters.Token), new KeyValuePair <string, string>(PostParameters.TokenSecure, doLoginResponse.TransferParameters.TokenSecure), }; return(content); }
public void RequiresTwoFactor() { DoLoginResponse doLoginResponse = new DoLoginResponse(); doLoginResponse.CaptchaNeeded = false; doLoginResponse.CaptchaGid = -1; doLoginResponse.Message = ""; doLoginResponse.RequiresTwoFactor = true; SkadiLoginErrorFactory.Create(doLoginResponse); var skadiLoginError = SkadiLoginErrorFactory.Create(doLoginResponse); Assert.Equal(ErrorType.TwoFactor, skadiLoginError.Type); }
private DoLoginResponse GetDoLoginResponse() { DoLoginResponse doLoginResponse = new DoLoginResponse(); TransferParameters transferParameters = new TransferParameters(); transferParameters.Auth = "b9wr1irasauno6rjngp3z2cfwf3qk3an"; transferParameters.RememberLogin = true; transferParameters.SteamId = "76561198028630048"; transferParameters.Token = "7ACRVJ9F3D1ETEN9HKFPWSEXZ3X020KRBEZ6HDA7"; transferParameters.TokenSecure = "O8W437FVTL29F9I31C6H48R0MBNAVIH5ILUMV4FW"; doLoginResponse.TransferParameters = transferParameters; return(doLoginResponse); }
public async Task <DoLoginResponse> DoLoginAsync(DoLoginRequest req) { HttpClientHandler handler = new HttpClientHandler { CookieContainer = new CookieContainer() }; using (HttpClient client = new HttpClient(handler)) { var p = new FormUrlEncodedContent(new[] { new KeyValuePair <string, string>("password", req.Password ?? string.Empty), new KeyValuePair <string, string>("username", req.Username ?? string.Empty), new KeyValuePair <string, string>("twofactorcode", req.TwoFactorCode ?? string.Empty), new KeyValuePair <string, string>("emailauth", req.EmailAuth ?? string.Empty), new KeyValuePair <string, string>("loginfriendlyname", req.LoginFriendlyName ?? string.Empty), new KeyValuePair <string, string>("captchagid", req.CaptchaGid.ToString()), new KeyValuePair <string, string>("captcha_text", req.CaptchaText ?? string.Empty), new KeyValuePair <string, string>("emailsteamid", req.EmailSteamId.HasValue ? req.EmailSteamId.Value.ToString() : string.Empty), new KeyValuePair <string, string>("rsatimestamp", req.RsaTimeStamp.ToString()), new KeyValuePair <string, string>("remember_login", req.RememberLogin.ToString().ToLowerInvariant()), }); HttpResponseMessage resp = await client.PostAsync(DoLoginPath, p); if (resp.IsSuccessStatusCode) { string respText = await resp.Content.ReadAsStringAsync(); DoLoginResponse respObj = JsonConvert.DeserializeObject <DoLoginResponse>(respText); if (req.RememberLogin && respObj.TransferParameters != null) { foreach (Cookie cookie in handler.CookieContainer.GetCookies(new Uri(BaseDomain))) { if (cookie.Name == "steamRememberLogin") { string[] bits = WebUtility.UrlDecode(cookie.Value).Split(new[] { "||" }, 2, StringSplitOptions.None); respObj.TransferParameters.RememberLoginToken = bits[1]; break; } } } return(respObj); } else { return(null); } } }
/// <summary> /// 获取数据 /// 默认显示前一天和今天,时间粒度为天 /// 访问量,访问人数,ip数,跳出率,平均访问时常 /// </summary> public JSON.Report.GetData.ReportResponse GetData(uint siteId, string method) { try { if (this.loginResponse == null || loginResponse.ReturnCode != 0) { // 重新登录 this.loginResponse = this.login.DoLogin(); } ReportRequest data = new ReportRequest(); data.Header.AccountType = "1"; data.Header.Password = this.loginResponse.ST; data.Header.Token = this.login.Token; data.Header.UserName = this.login.UserName; data.Body = new BodyRequest(); data.Body.Method = method; data.Body.SiteId = siteId; data.Body.StartDate = DateTime.Now.AddDays(-2); data.Body.EndDate = DateTime.Now; data.Body.Metrics.Add(Metrics.PageViewCount); data.Body.Metrics.Add(Metrics.VisitorCount); data.Body.Metrics.Add(Metrics.IPCount); data.Body.Metrics.Add(Metrics.BounceRatio); data.Body.Metrics.Add(Metrics.AVGVisitTime); data.Body.Gran = Gran.Hour; string value = HttpManager.RequestReport(Report.URL + "/getData", this.loginResponse.UCID, data); JSON.Report.GetData.ReportResponse response = JsonConvert.DeserializeObject <JSON.Report.GetData.ReportResponse>(value); return(response); } catch { throw; } finally { if (this.loginResponse != null || loginResponse.ReturnCode == 0) { // 登出 this.login.DoLogout(this.loginResponse.UCID, this.loginResponse.ST); } } }
private DoLoginResponse DoLogin(GetRsaKeyResponse getRsaKeyResponse, string username, string password, string sharedSecret) { DoLoginResponse doLoginResponse = null; var encryptedPassword = EncryptPasswordFactory.Create(getRsaKeyResponse, password); var content = PostDataFactory.CreateDoLoginData(username, encryptedPassword, getRsaKeyResponse.Timestamp, TwoFactorCodeFactory.Create(sharedSecret)); var response = _requestFactory.Create(HttpMethod.POST, Uris.SteamCommunitySecureBase, SteamCommunityEndpoints.DoLogin, Accept.All, HttpHeaderValues.AcceptLanguageOne, false, true, true, true, false, content); string responseContent = response.Content.ReadAsStringAsync().Result; doLoginResponse = JsonConvert.DeserializeObject <DoLoginResponse>(responseContent); return(doLoginResponse); }
internal static bool IsValid(DoLoginResponse doLoginResponse) { return(doLoginResponse.Success && doLoginResponse.LoginComplete); }
private SkadiLoginResponse ExecuteUntilLogin(SkadiLoginData skadiLoginData) { GetSession(); GetRsaKeyResponse rsaKey = new GetRsaKeyResponse(); DoLoginResponse doLoginResponse = new DoLoginResponse(); var doLoginSuccessful = false; do { try { rsaKey = GetRsaKey(skadiLoginData.Username); doLoginResponse = DoLogin(rsaKey, skadiLoginData.Username, skadiLoginData.Password, skadiLoginData.SharedSecret); if (!DoLoginResponseValidator.IsValid(doLoginResponse)) { if (doLoginResponse.CaptchaNeeded) { // TODO: Get exact time for cooldown of captcha! Task.Delay(TimeSpan.FromMinutes(25)); } rsaKey = null; doLoginResponse = null; } else { doLoginSuccessful = true; } } catch (Exception) { Task.Delay( TimeSpan.FromSeconds( _skadiLoginConfiguration.WaitTimeEachError)).Wait(); } }while (doLoginSuccessful == false); bool errorInTransfer = false; do { try { Transfer(doLoginResponse); } catch (Exception) { errorInTransfer = true; Task.Delay(TimeSpan.FromSeconds(5)).Wait(); } } while (errorInTransfer); SkadiLoginResponse skadiLoginResponse = null; do { try { skadiLoginResponse = SetSession(); } catch (Exception) { Task.Delay(TimeSpan.FromSeconds(5)).Wait(); } } while (skadiLoginResponse == null); return(skadiLoginResponse); }
async Task <bool> doLogin() { // Assume validity checks have been done // 1. Get RSA key GetRsaKeyResponse rsaResponse = await loginClient.GetRsaKeyAsync(usernameTextBox.Text); if (!rsaResponse.Success) { setMessage(!string.IsNullOrEmpty(rsaResponse.Message) ? rsaResponse.Message : "Can't get RSA key for sending login info."); return(false); } // 2. Encrypt password string encryptedPassword; using (var rsa = new RSACryptoServiceProvider()) { rsa.ImportParameters(new RSAParameters { Modulus = hexToBytes(rsaResponse.PublicKeyMod), Exponent = hexToBytes(rsaResponse.PublicKeyExp) }); // Filter password to ASCII characters (the login script does this) string password = System.Text.RegularExpressions.Regex.Replace(passwordTextBox.Text, "[^\u0000-\u007F]", string.Empty); byte[] passwordBlob = Encoding.UTF8.GetBytes(password); byte[] crypted = rsa.Encrypt(passwordBlob, false); encryptedPassword = Convert.ToBase64String(crypted); } // 3. Send request to server DoLoginRequest request = new DoLoginRequest { Password = encryptedPassword, Username = usernameTextBox.Text, TwoFactorCode = mobileAuthTextBox.Text, EmailAuth = emailAuthTextBox.Text, LoginFriendlyName = friendlyNameTextBox.Text, CaptchaText = captchaTextBox.Text, RsaTimeStamp = rsaResponse.Timestamp, RememberLogin = true }; if (loginResponse != null) { request.CaptchaGid = loginResponse.CaptchaGid; request.EmailSteamId = loginResponse.EmailSteamId; } else { request.CaptchaGid = -1; } loginResponse = await loginClient.DoLoginAsync(request); if (loginResponse == null) { return(false); } return(loginResponse.Success && loginResponse.LoginComplete); }