private void Button_Click(object sender, RoutedEventArgs e) { this.LoginFailedTextBlock.Visibility = Visibility.Hidden; Cookie receivedCookie = null; Cookie twofaCookie = null; bool authresult = false; try { authresult = (this.PasswordBox.Password.Length > 7 && LogInForm.AuthenticateUser(this.EmailTextBox.Text, this.PasswordBox.Password, this.TwoFABox.Password, out receivedCookie, out twofaCookie)); } catch (Exception ex) { LogHost.Default.InfoException("An exception occured while trying to log in", ex); } if (authresult) { base.DialogResult = new bool?(true); if (receivedCookie != null) { this.receivedCookies.Add(receivedCookie); } if (twofaCookie != null) { this.receivedCookies.Add(twofaCookie); } Settings.Default.Cookies = Convert.ToBase64String(LogInForm.ObjectToByteArray(this.receivedCookies)); Settings.Default.Save(); base.Close(); return; } this.LoginFailedTextBlock.Visibility = Visibility.Visible; }
private static bool AuthenticateUser(string user, string password, string twofa, out Cookie authCookie, out Cookie twofaCookie) { HttpWebRequest request = (HttpWebRequest)WebRequest.Create(new Uri("https://xivhunt.net/Account/RemoteLogin")); request.Method = "POST"; request.ContentType = "application/x-www-form-urlencoded"; request.CookieContainer = new CookieContainer(); request.AllowAutoRedirect = true; string authCredentials = string.Concat(new string[] { "Email=", WebUtility.UrlEncode(user), "&Password="******"&RememberMe=true" }); if (!string.IsNullOrWhiteSpace(twofa)) { authCredentials = authCredentials + "&TwoFactorCode=" + twofa; } byte[] bytes = Encoding.UTF8.GetBytes(authCredentials); request.ContentLength = (long)bytes.Length; using (Stream requestStream = request.GetRequestStream()) { requestStream.Write(bytes, 0, bytes.Length); } using (HttpWebResponse response = (HttpWebResponse)request.GetResponse()) { authCookie = response.Cookies[".AspNetCore.Identity.Application"]; if (authCookie == null && !string.IsNullOrWhiteSpace(twofa) && response.Cookies["Identity.TwoFactorUserId"] != null) { LogInForm.TwoFA(twofa, response.Cookies["Identity.TwoFactorUserId"], out authCookie, out twofaCookie); } else { twofaCookie = null; } } return(authCookie != null); }
internal CookieContainer Login(ushort sid) { CookieContainer cc = null; if (!string.IsNullOrWhiteSpace(Settings.Default.Cookies)) { cc = (CookieContainer)ByteArrayToObject(Convert.FromBase64String(Settings.Default.Cookies)); } while (!TestCC(cc)) { var lif = new UI.LogInForm(sid); if ((bool)lif.ShowDialog() && lif.receivedCookies.Count > 0) { cc = lif.receivedCookies; } if (lif.receivedCookies.Count == 0) { Environment.Exit(0); } } return(cc); }