/// <summary> /// Click to create a enroll a new authenticator /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void enrollAuthenticatorButton_Click(object sender, EventArgs e) { do { try { newSerialNumberField.Text = "creating..."; TrionAuthenticator authenticator = new TrionAuthenticator(); #if DEBUG authenticator.Enroll(System.Diagnostics.Debugger.IsAttached); #else authenticator.Enroll(); #endif this.Authenticator.AuthenticatorData = authenticator; newSerialNumberField.Text = authenticator.Serial; newLoginCodeField.Text = authenticator.CurrentCode; newRestoreCodeField.Text = authenticator.DeviceId; return; } catch (InvalidEnrollResponseException iere) { if (WinAuthForm.ErrorDialog(this.Owner, "An error occured while registering a new authenticator", iere, MessageBoxButtons.RetryCancel) != System.Windows.Forms.DialogResult.Retry) { break; } } } while (true); clearAuthenticator(false); }
/// <summary> /// Reject the trade Confirmation /// </summary> /// <param name="tradeId">ID of Confirmation</param> private void RejectTrade(string tradeId) { try { var trade = m_trades.Where(t => t.Id == tradeId).FirstOrDefault(); if (trade == null) { WinAuthForm.ErrorDialog(this, "Invalid trade"); return; } var result = this.AuthenticatorData.GetClient().ConfirmTrade(trade.Id, trade.Key, false); if (result == false) { WinAuthForm.ErrorDialog(this, "Trade cannot be cancelled"); } else { m_trades.Remove(trade); MetroButton button = FindControl <MetroButton>(tabs.SelectedTab, "tradeAccept_" + trade.Id); button.Visible = false; button = FindControl <MetroButton>(tabs.SelectedTab, "tradeReject_" + trade.Id); button.Visible = false; MetroLabel status = FindControl <MetroLabel>(tabs.SelectedTab, "tradeStatus_" + trade.Id); status.Text = "Cancelled"; status.Visible = true; } } catch (InvalidTradesResponseException ex) { WinAuthForm.ErrorDialog(this, "Error trying to reject trade", ex, MessageBoxButtons.OK); } }
/// <summary> /// Check the configuration with the current yubikey /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void yubikeyCheckButton_Click(object sender, EventArgs e) { if (WinAuthForm.ConfirmDialog(this, "Your YubiKey slot will now be verified. If it requires you to press the button, please press when the light starts flashing." + Environment.NewLine + Environment.NewLine + "Continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning) != System.Windows.Forms.DialogResult.Yes) { return; } int slot = (yubiSlotToggle.Checked == true ? 2 : 1); try { byte[] challenge = Encoding.ASCII.GetBytes("WinAuth"); // get the hash from the key byte[] hash = this.Yubikey.ChallengeResponse(slot, challenge); } catch (ApplicationException ex) { WinAuthForm.ErrorDialog(this, "The YubiKey test failed. Please check the configuration is for Challenge-Response in HMAC-SHA1 mode with Variable Input. (" + ex.Message + ")"); return; } YubikeySlot = slot; WinAuthForm.ErrorDialog(this, "Your YubiKey has been successfully tested."); }
/// <summary> /// Click to get they security questions /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void restoreGetQuestionsButton_Click(object sender, EventArgs e) { string email = this.restoreEmailField.Text.Trim(); string password = this.restorePasswordField.Text.Trim(); if (email.Length == 0 || password.Length == 0) { WinAuthForm.ErrorDialog(this.Owner, "Please enter your account email and password"); return; } try { string question1, question2; TrionAuthenticator.SecurityQuestions(email, password, out question1, out question2); restoreQuestion1Label.Text = question1 ?? string.Empty; restoreQuestion2Label.Text = question2 ?? string.Empty; } catch (InvalidRestoreResponseException irre) { WinAuthForm.ErrorDialog(this.Owner, irre.Message, irre); return; } catch (Exception ex) { WinAuthForm.ErrorDialog(this.Owner, "Unable to access account: " + ex.Message, ex); return; } }
/// <summary> /// Clear the authenticator and any associated fields /// </summary> /// <param name="showWarning"></param> private void clearAuthenticator(bool showWarning = true) { if (this.Authenticator.AuthenticatorData != null && showWarning == true) { DialogResult result = WinAuthForm.ConfirmDialog(this.Owner, "这将清除您刚刚创建的验证器。 " + "如果您已将此验证器附加到您的帐户,您可能无法在将来登录。" + Environment.NewLine + Environment.NewLine + "你确定你要继续吗?"); if (result != System.Windows.Forms.DialogResult.Yes) { return; } this.Authenticator.AuthenticatorData = null; } newAuthenticatorProgress.Visible = false; newAuthenticatorTimer.Enabled = false; newSerialNumberField.Text = string.Empty; newSerialNumberField.SecretMode = true; newLoginCodeField.Text = string.Empty; newLoginCodeField.SecretMode = true; newRestoreCodeField.Text = string.Empty; newRestoreCodeField.SecretMode = true; allowCopyNewButton.Checked = false; restoreSerialNumberField.Text = string.Empty; restoreRestoreCodeField.Text = string.Empty; importPrivateKeyField.Text = string.Empty; }
/// <summary> /// Click the OK button to verify and add the authenticator /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void okButton_Click(object sender, EventArgs e) { var privatekey = secretCodeField.Text.Trim(); if (privatekey.Length == 0) { WinAuthForm.ErrorDialog(Owner, "Please enter the Secret Code"); DialogResult = DialogResult.None; return; } var first = Authenticator.AuthenticatorData == null; if (verifyAuthenticator(privatekey) == false) { DialogResult = DialogResult.None; return; } if (first) { DialogResult = DialogResult.None; return; } // if this is a htop we reduce the counter because we are going to immediate get the code and increment if (Authenticator.AuthenticatorData is HOTPAuthenticator) { ((HOTPAuthenticator)Authenticator.AuthenticatorData).Counter--; } }
/// <summary> /// Click the OK button to verify and add the authenticator /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void okButton_Click(object sender, EventArgs e) { string privatekey = this.secretCodeField.Text.Trim(); if (privatekey.Length == 0) { WinAuthForm.ErrorDialog(this.Owner, "Please enter the Secret Code"); this.DialogResult = System.Windows.Forms.DialogResult.None; return; } bool first = (this.Authenticator.AuthenticatorData == null); if (verifyAuthenticator(privatekey) == false) { this.DialogResult = System.Windows.Forms.DialogResult.None; return; } if (first == true) { this.DialogResult = System.Windows.Forms.DialogResult.None; return; } // if this is a htop we reduce the counter because we are going to immediate get the code and increment if (this.Authenticator.AuthenticatorData is HOTPAuthenticator) { ((HOTPAuthenticator)this.Authenticator.AuthenticatorData).Counter--; } }
/// <summary> /// Click to create a enroll a new authenticator /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void enrollAuthenticatorButton_Click(object sender, EventArgs e) { do { try { newSerialNumberField.Text = "creating..."; BattleNetAuthenticator authenticator = new BattleNetAuthenticator(); #if DEBUG authenticator.Enroll(System.Diagnostics.Debugger.IsAttached); #else authenticator.Enroll(); #endif this.Authenticator.AuthenticatorData = authenticator; newSerialNumberField.Text = authenticator.Serial; newLoginCodeField.Text = authenticator.CurrentCode; newRestoreCodeField.Text = authenticator.RestoreCode; newAuthenticatorProgress.Visible = true; newAuthenticatorTimer.Enabled = true; return; } catch (InvalidEnrollResponseException iere) { if (WinAuthForm.ErrorDialog(this.Owner, "注册新的验证器时发生错误", iere, MessageBoxButtons.RetryCancel) != System.Windows.Forms.DialogResult.Retry) { break; } } } while (true); clearAuthenticator(false); }
/// <summary> /// Clear the authenticator and any associated fields /// </summary> /// <param name="showWarning"></param> private void clearAuthenticator(bool showWarning = true) { if (this.Authenticator.AuthenticatorData != null && showWarning == true) { DialogResult result = WinAuthForm.ConfirmDialog(this.Owner, "这将清除您刚刚创建的验证器. " + "如果您已将此验证器附加到您的帐户,您可能无法在将来登录." + Environment.NewLine + Environment.NewLine + "你确定你要继续吗?"); if (result != System.Windows.Forms.DialogResult.Yes) { return; } this.Authenticator.AuthenticatorData = null; } newSerialNumberField.Text = string.Empty; newSerialNumberField.SecretMode = true; newLoginCodeField.Text = string.Empty; newLoginCodeField.SecretMode = true; newRestoreCodeField.Text = string.Empty; newRestoreCodeField.SecretMode = true; allowCopyNewButton.Checked = false; restoreEmailField.Text = string.Empty; restorePasswordField.Text = string.Empty; restoreDeviceIdField.Text = string.Empty; restoreQuestion1Label.Text = string.Empty; restoreQuestion2Label.Text = string.Empty; restoreAnswer1Field.Text = string.Empty; restoreAnswer2Field.Text = string.Empty; }
private static void main() { #if NETFX_45 // Fix #226: set to use TLS1.2 try { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; } catch (Exception) { // not 4.5 installed - we could prompt, but not for now } #endif // Issue #53: set a default culture if (System.Threading.Thread.CurrentThread.CurrentCulture == null || System.Threading.Thread.CurrentThread.CurrentUICulture == null) { CultureInfo ci = new CultureInfo("en"); // or en-US, en-GB System.Threading.Thread.CurrentThread.CurrentCulture = ci; System.Threading.Thread.CurrentThread.CurrentUICulture = ci; } strings.Culture = System.Threading.Thread.CurrentThread.CurrentUICulture; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); _form = new WinAuthForm(); Application.Run(_form); }
/// <summary> /// Clear the authenticator and any associated fields /// </summary> /// <param name="showWarning"></param> private void clearAuthenticator(bool showWarning = true) { if (this.Authenticator.AuthenticatorData != null && showWarning == true) { DialogResult result = WinAuthForm.ConfirmDialog(this.Owner, "This will clear the authenticator you have just created. " + "If you have attached this authenticator to your account, you might not be able to login in the future." + Environment.NewLine + Environment.NewLine + "Are you sure you want to continue?"); if (result != System.Windows.Forms.DialogResult.Yes) { return; } this.Authenticator.AuthenticatorData = null; } newSerialNumberField.Text = string.Empty; newSerialNumberField.SecretMode = true; newLoginCodeField.Text = string.Empty; newLoginCodeField.SecretMode = true; newRestoreCodeField.Text = string.Empty; newRestoreCodeField.SecretMode = true; allowCopyNewButton.Checked = false; restoreEmailField.Text = string.Empty; restorePasswordField.Text = string.Empty; restoreDeviceIdField.Text = string.Empty; restoreQuestion1Label.Text = string.Empty; restoreQuestion2Label.Text = string.Empty; restoreAnswer1Field.Text = string.Empty; restoreAnswer2Field.Text = string.Empty; }
/// <summary> /// Click the OK button to verify and add the authenticator /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void okButton_Click(object sender, EventArgs e) { var privatekey = secretCodeField.Text.Trim(); if (privatekey.Length == 0) { WinAuthForm.ErrorDialog(Owner, "Please enter the Secret Code"); DialogResult = DialogResult.None; return; } var first = !newAuthenticatorProgress.Visible; if (verifyAuthenticator(privatekey) == false) { DialogResult = DialogResult.None; return; } if (first) { DialogResult = DialogResult.None; return; } if (Authenticator.AuthenticatorData == null) { WinAuthForm.ErrorDialog(Owner, "Please enter the Secret Code and click Verify Authenticator"); DialogResult = DialogResult.None; } }
/// <summary> /// Change the poller action /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void pollAction_SelectedIndexChanged(object sender, EventArgs e) { // display autoconfirm warning if (m_loaded && pollAction.SelectedValue != null && pollAction.SelectedValue is SteamClient.PollerAction && ((SteamClient.PollerAction)pollAction.SelectedValue == SteamClient.PollerAction.AutoConfirm || (SteamClient.PollerAction)pollAction.SelectedValue == SteamClient.PollerAction.SilentAutoConfirm) && AutoWarned == false) { if (WinAuthForm.ConfirmDialog(this, "WARNING: Using auto-confirm will automatically confirm all new Confirmations on your " + "account. Do not use this unless you want to ignore trade confirmations." + Environment.NewLine + Environment.NewLine + "This WILL remove items from your inventory." + Environment.NewLine + Environment.NewLine + "Are you sure you want to continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.Yes) { pollAction.SelectedIndex = 0; } else { AutoWarned = true; } } }
/// <summary> /// Clear the authenticator and any associated fields /// </summary> /// <param name="showWarning"></param> private void clearAuthenticator(bool showWarning = true) { if (Authenticator.AuthenticatorData != null && showWarning) { var result = WinAuthForm.ConfirmDialog(Owner, "This will clear the authenticator you have just created. " + "If you have attached this authenticator to your account, you might not be able to login in the future." + Environment.NewLine + Environment.NewLine + "Are you sure you want to continue?"); if (result != DialogResult.Yes) { return; } Authenticator.AuthenticatorData = null; } newAuthenticatorProgress.Visible = false; newAuthenticatorTimer.Enabled = false; newSerialNumberField.Text = string.Empty; newSerialNumberField.SecretMode = true; newLoginCodeField.Text = string.Empty; newLoginCodeField.SecretMode = true; newRestoreCodeField.Text = string.Empty; newRestoreCodeField.SecretMode = true; allowCopyNewButton.Checked = false; restoreSerialNumberField.Text = string.Empty; restoreRestoreCodeField.Text = string.Empty; importPrivateKeyField.Text = string.Empty; }
/// <summary> /// Click the OK button to verify and add the authenticator /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void okButton_Click(object sender, EventArgs e) { string privatekey = this.secretCodeField.Text.Trim(); if (privatekey.Length == 0) { WinAuthForm.ErrorDialog(this.Owner, "Please enter the Secret Code"); this.DialogResult = System.Windows.Forms.DialogResult.None; return; } bool first = !newAuthenticatorProgress.Visible; if (verifyAuthenticator(privatekey) == false) { this.DialogResult = System.Windows.Forms.DialogResult.None; return; } if (first == true) { this.DialogResult = System.Windows.Forms.DialogResult.None; return; } if (this.Authenticator.AuthenticatorData == null) { WinAuthForm.ErrorDialog(this.Owner, "Please enter the Secret Code and click Verify Authenticator"); this.DialogResult = System.Windows.Forms.DialogResult.None; return; } }
/// <summary> /// Login to steam account /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void loginButton_Click(object sender, EventArgs e) { if (usernameField.Text.Trim().Length == 0 || passwordField.Text.Trim().Length == 0) { WinAuthForm.ErrorDialog(this, "Please enter your username and password", null, MessageBoxButtons.OK); return; } Process(usernameField.Text.Trim(), passwordField.Text.Trim()); }
/// <summary> /// Answer the captcha /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void captchaButton_Click(object sender, EventArgs e) { if (captchacodeField.Text.Trim().Length == 0) { WinAuthForm.ErrorDialog(this, "Please enter the characters in the image", null, MessageBoxButtons.OK); return; } Process(usernameField.Text.Trim(), passwordField.Text.Trim(), this.AuthenticatorData.GetClient().CaptchaId, captchacodeField.Text.Trim()); }
/// <summary> /// Click verify button to load and check code /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void verifyButton_Click(object sender, EventArgs e) { string privatekey = this.secretCodeField.Text.Trim(); if (privatekey.Length == 0) { WinAuthForm.ErrorDialog(this.Owner, "Please enter the Secret Code"); return; } verifyAuthenticator(privatekey); }
/// <summary> /// Confirm with the code sent by email /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void authcodeButton_Click(object sender, EventArgs e) { if (authcodeField.Text.Trim().Length == 0) { WinAuthForm.ErrorDialog(this, "请输入授权代码", null, MessageBoxButtons.OK); return; } m_enroll.EmailAuthText = authcodeField.Text.Trim(); ProcessEnroll(); }
/// <summary> /// Confirm with the code sent by email /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void authcodeButton_Click(object sender, EventArgs e) { if (authcodeField.Text.Trim().Length == 0) { WinAuthForm.ErrorDialog(this, "Please enter the authorisation code"); return; } m_enroll.EmailAuthText = authcodeField.Text.Trim(); ProcessEnroll(); }
/// <summary> /// OK button is clicked /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void okButton_Click(object sender, EventArgs e) { // check password is set if requried if (passwordCheckbox.Checked == true && passwordField.Text.Trim().Length == 0) { WinAuthForm.ErrorDialog(this, strings.EnterPassword); this.DialogResult = System.Windows.Forms.DialogResult.None; return; } if (passwordCheckbox.Checked == true && string.Compare(passwordField.Text.Trim(), verifyField.Text.Trim()) != 0) { WinAuthForm.ErrorDialog(this, strings.PasswordsDontMatch); this.DialogResult = System.Windows.Forms.DialogResult.None; return; } if (yubikeyBox.Checked == true && YubikeySlot == 0 && (PasswordType & (Authenticator.PasswordTypes.YubiKeySlot1 | Authenticator.PasswordTypes.YubiKeySlot2)) == 0) { WinAuthForm.ErrorDialog(this, "Please verify your YubiKey using the Use Slot or Configure Slot buttons."); this.DialogResult = System.Windows.Forms.DialogResult.None; return; } // set the valid password type property PasswordType = Authenticator.PasswordTypes.None; Password = null; if (userCheckbox.Checked == true) { PasswordType |= Authenticator.PasswordTypes.User; } else if (machineCheckbox.Checked == true) { PasswordType |= Authenticator.PasswordTypes.Machine; } if (passwordCheckbox.Checked == true) { PasswordType |= Authenticator.PasswordTypes.Explicit; if (this.passwordField.Text != EXISTING_PASSWORD) { Password = this.passwordField.Text.Trim(); } } if (yubikeyBox.Checked == true) { if (YubikeySlot == 1) { PasswordType |= Authenticator.PasswordTypes.YubiKeySlot1; } else if (YubikeySlot == 2) { PasswordType |= Authenticator.PasswordTypes.YubiKeySlot2; } } }
/// <summary> /// Click to add the code /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void verifyAuthenticatorButton_Click(object sender, EventArgs e) { string privatekey = this.secretCodeField.Text.Trim(); if (string.IsNullOrEmpty(privatekey) == true) { WinAuthForm.ErrorDialog(this, "Please enter the secret code"); return; } verifyAuthenticator(privatekey); }
/// <summary> /// Click the button to cancel all confirmations /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void cancelAllButton_Click(object sender, EventArgs e) { if (WinAuthForm.ConfirmDialog(this, "This will CANCEL all your current trade confirmations." + Environment.NewLine + Environment.NewLine + "Are you sure you want to continue?", MessageBoxButtons.YesNo, MessageBoxIcon.Warning, MessageBoxDefaultButton.Button2) != DialogResult.Yes) { return; } var cursor = Cursor.Current; try { Cursor.Current = Cursors.WaitCursor; Application.DoEvents(); cancelAllButton.Text = "Stop"; confirmAllButton.Enabled = false; closeButton.Enabled = false; var rand = new Random(); var tradeIds = m_trades.Select(t => t.Id).Reverse().ToArray(); for (var i = tradeIds.Length - 1; i >= 0; i--) { DateTime start = DateTime.Now; var result = RejectTrade(tradeIds[i]); if (result == false) { break; } if (i != 0) { var duration = (int)DateTime.Now.Subtract(start).TotalMilliseconds; var delay = SteamClient.CONFIRMATION_EVENT_DELAY + rand.Next(SteamClient.CONFIRMATION_EVENT_DELAY / 2); // delay is 100%-150% of CONFIRMATION_EVENT_DELAY if (delay > duration) { Thread.Sleep(delay - duration); } } } } finally { confirmAllButton.Enabled = true; closeButton.Enabled = true; this.Authenticator.MarkChanged(); Cursor.Current = cursor; } }
/// <summary> /// Click the OK button to verify and add the authenticator /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void confirmButton_Click(object sender, EventArgs e) { if (activationcodeField.Text.Trim().Length == 0) { WinAuthForm.ErrorDialog(this, "Please enter the activation code from your email"); DialogResult = DialogResult.None; return; } m_enroll.ActivationCode = activationcodeField.Text.Trim(); ProcessEnroll(); }
/// <summary> /// Click the OK button to verify and add the authenticator /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void confirmButton_Click(object sender, EventArgs e) { if (activationcodeField.Text.Trim().Length == 0) { WinAuthForm.ErrorDialog(this, "请从电子邮件中输入激活码"); this.DialogResult = System.Windows.Forms.DialogResult.None; return; } m_enroll.ActivationCode = activationcodeField.Text.Trim(); ProcessEnroll(); }
/// <summary> /// Login to steam account /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void loginButton_Click(object sender, EventArgs e) { if (usernameField.Text.Trim().Length == 0 || passwordField.Text.Trim().Length == 0) { WinAuthForm.ErrorDialog(this, "请输入您的用户名和密码", null, MessageBoxButtons.OK); return; } m_enroll.Username = usernameField.Text.Trim(); m_enroll.Password = passwordField.Text.Trim(); ProcessEnroll(); }
/// <summary> /// Login to steam account /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void loginButton_Click(object sender, EventArgs e) { if (usernameField.Text.Trim().Length == 0 || passwordField.Text.Trim().Length == 0) { WinAuthForm.ErrorDialog(this, "Please enter your username and password"); return; } m_enroll.Username = usernameField.Text.Trim(); m_enroll.Password = passwordField.Text.Trim(); ProcessEnroll(); }
/// <summary> /// Answer the captcha /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void captchaButton_Click(object sender, EventArgs e) { if (captchacodeField.Text.Trim().Length == 0) { WinAuthForm.ErrorDialog(this, "请在图像中输入字符", null, MessageBoxButtons.OK); return; } m_enroll.Username = usernameField.Text.Trim(); m_enroll.Password = passwordField.Text.Trim(); m_enroll.CaptchaText = captchacodeField.Text.Trim(); ProcessEnroll(); }
/// <summary> /// Import the selected SDA account /// </summary> /// <returns>true if successful</returns> private bool ImportSDA() { var entry = importSDAList.SelectedItem as ImportedSDAEntry; if (entry == null) { WinAuthForm.ErrorDialog(this, "Please load and select a Steam account"); return(false); } var auth = new SteamAuthenticator(); var token = JObject.Parse(entry.json); foreach (var prop in token.Root.Children().ToList()) { var child = token.SelectToken(prop.Path); var lkey = prop.Path.ToLower(); if (lkey == "fully_enrolled" || lkey == "session") { prop.Remove(); } else if (lkey == "device_id") { auth.DeviceId = child.Value <string>(); prop.Remove(); } else if (lkey == "serial_number") { auth.Serial = child.Value <string>(); } else if (lkey == "account_name") { if (nameField.Text.Length == 0) { nameField.Text = "Steam (" + child.Value <string>() + ")"; } } else if (lkey == "shared_secret") { auth.SecretKey = Convert.FromBase64String(child.Value <string>()); } } auth.SteamData = token.ToString(Formatting.None); Authenticator.AuthenticatorData = auth; return(true); }
/// <summary> /// Answer the captcha /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void captchaButton_Click(object sender, EventArgs e) { if (captchacodeField.Text.Trim().Length == 0) { WinAuthForm.ErrorDialog(this, "Please enter the characters in the image"); return; } m_enroll.Username = usernameField.Text.Trim(); m_enroll.Password = passwordField.Text.Trim(); m_enroll.CaptchaText = captchacodeField.Text.Trim(); ProcessEnroll(); }
private static void main() { // Issue #53: set a default culture if (System.Threading.Thread.CurrentThread.CurrentCulture == null || System.Threading.Thread.CurrentThread.CurrentUICulture == null) { CultureInfo ci = new CultureInfo("en"); // or en-US, en-GB System.Threading.Thread.CurrentThread.CurrentCulture = ci; System.Threading.Thread.CurrentThread.CurrentUICulture = ci; } strings.Culture = System.Threading.Thread.CurrentThread.CurrentUICulture; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); _form = new WinAuthForm(); Application.Run(_form); }
private static void main() { // Fix #226: set to use TLS1.2 try { ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls | SecurityProtocolType.Tls11 | SecurityProtocolType.Tls12; } catch (Exception) { // not 4.5 installed - we could prompt, but not for now } // Issue #53: set a default culture if (System.Threading.Thread.CurrentThread.CurrentCulture == null || System.Threading.Thread.CurrentThread.CurrentUICulture == null) { CultureInfo ci = new CultureInfo("en"); // or en-US, en-GB System.Threading.Thread.CurrentThread.CurrentCulture = ci; System.Threading.Thread.CurrentThread.CurrentUICulture = ci; } strings.Culture = System.Threading.Thread.CurrentThread.CurrentUICulture; Application.EnableVisualStyles(); Application.SetCompatibleTextRenderingDefault(false); _form = new WinAuthForm(); Application.Run(_form); }
/// <summary> /// Send the keys to the expected window or current window if null /// </summary> /// <param name="keys">stirng to send</param> public void SendKeys(WinAuthForm form, string keys, string code) { if (m_hWnd != IntPtr.Zero && m_hWnd != WinAPI.GetForegroundWindow()) { WinAPI.SetForegroundWindow(m_hWnd); System.Threading.Thread.Sleep(50); } // replace any {CODE} items keys = Regex.Replace(keys, @"\{\s*CODE\s*\}", code, RegexOptions.Singleline); // clear events and stop input Application.DoEvents(); bool blocked = WinAPI.BlockInput(true); try { // for now just split into parts and run each foreach (Match match in Regex.Matches(keys, @"\{.*?\}|[^\{]*", RegexOptions.Singleline)) { // split into either {CMD d w} or just plain text if (match.Success == true) { string single = match.Value; if (single.Length == 0) { continue; } if (single[0] == '{') { // send command {COMMAND delay repeat} Match cmdMatch = Regex.Match(single.Trim(), @"\{([^\s]+)\s*(\d*)\s*(\d*)\}"); if (cmdMatch.Success == true) { // extract the command and any optional delay and repeat string cmd = cmdMatch.Groups[1].Value.ToUpper(); int delay = 0; if (cmdMatch.Groups[2].Success == true && cmdMatch.Groups[2].Value.Length != 0) { int.TryParse(cmdMatch.Groups[2].Value, out delay); } int repeat = 1; if (cmdMatch.Groups[3].Success == true && cmdMatch.Groups[3].Value.Length != 0) { int.TryParse(cmdMatch.Groups[3].Value, out repeat); } // run the command switch (cmd) { case "BS": SendKey('\x08', delay, repeat); break; case "TAB": SendKey('\t', delay, repeat); break; case "ENTER": SendKey('\n', delay, repeat); break; case "WAIT": for (; repeat > 0; repeat--) { System.Threading.Thread.Sleep(delay); } break; case "COPY": form.Invoke(new WinAuthForm.SetClipboardDataDelegate(form.SetClipboardData), new object[] { code }); break; case "PASTE": string clipboard = form.Invoke(new WinAuthForm.GetClipboardDataDelegate(form.GetClipboardData), new object[] { typeof(string) }) as string; if (string.IsNullOrEmpty(clipboard) == false) { foreach (char key in clipboard) { SendKey(key); } } break; case "EXIT": Application.Exit(); break; default: break; } } } else { SendKey(single); } } } } finally { // resume input if (blocked == true) { WinAPI.BlockInput(false); } Application.DoEvents(); } }
/// <summary> /// Create a new HotKeyLauncher object /// </summary> /// <param name="form">owning Form</param> /// <param name="auth">Authenticator</param> public HotKeyLauncher(WinAuthForm form, WinAuthAuthenticator auth) { Started = DateTime.Now; Form = form; Authenticator = auth; }