public void GlobalLoginAttempt(string user, string pass, string tfa) { if (Trying) { MessageBox.Show("Already attempting a login...", "Error"); return; } Trying = true; changeLogin.Enabled = false; progressBar1.Enabled = true; progressBar1.Style = ProgressBarStyle.Marquee; Task.Factory.StartNew(() => { using (ShortWebClient wb = new ShortWebClient()) { try { NameValueCollection data = new NameValueCollection(); data["formtype"] = "login"; data["username"] = user; data["password"] = pass; data["tfa_code"] = tfa; data["session_id"] = "0"; byte[] response = wb.UploadValues(GlobalServerAddress + "account/micrologin", "POST", data); string resp = encoding.GetString(response).Trim(' ', '\n', '\r', '\t'); if (resp.StartsWith("ACCEPT=") && resp.EndsWith(";")) { string key = resp.Substring("ACCEPT=".Length, resp.Length - 1 - "ACCEPT=".Length); Invoke(new Action(() => { changeLogin.Enabled = true; progressBar1.Enabled = false; progressBar1.Style = ProgressBarStyle.Blocks; Trying = false; File.WriteAllText("logindata.dat", user + "=" + key); UserName = user; FixButtons(); })); } else { Invoke(new Action(() => { changeLogin.Enabled = true; progressBar1.Enabled = false; progressBar1.Style = ProgressBarStyle.Blocks; Trying = false; MessageBox.Show("Login refused: " + resp); Logout(); })); } } catch (Exception ex) { Invoke(new Action(() => { changeLogin.Enabled = true; progressBar1.Enabled = false; progressBar1.Style = ProgressBarStyle.Blocks; Trying = false; MessageBox.Show("Login failed: " + ex.ToString()); Logout(); })); } } }); }