/// <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>
        /// 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);
        }
Example #3
0
        /// <summary>
        /// Form loaded event
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void ShowTrionSecretForm_Load(object sender, EventArgs e)
        {
            this.serialNumberField.SecretMode = true;
            this.deviceIdField.SecretMode     = true;

            TrionAuthenticator authenticator = CurrentAuthenticator.AuthenticatorData as TrionAuthenticator;

            this.serialNumberField.Text = authenticator.Serial;
            this.deviceIdField.Text     = authenticator.DeviceId;
        }
        /// <summary>
        /// Verify and create the authenticator if needed
        /// </summary>
        /// <returns>true is successful</returns>
        private bool verifyAuthenticator()
        {
            if (this.tabControl1.SelectedIndex == 0)
            {
                if (this.Authenticator.AuthenticatorData == null)
                {
                    WinAuthForm.ErrorDialog(this.Owner, "You need to create an authenticator and attach it to your account");
                    return(false);
                }
            }
            else
            {
                if (restoreQuestion1Label.Text.Length == 0)
                {
                    restoreGetQuestionsButton_Click(null, null);
                    return(false);
                }

                string email    = this.restoreEmailField.Text.Trim();
                string password = this.restorePasswordField.Text.Trim();
                string deviceId = this.restoreDeviceIdField.Text.Trim();
                string answer1  = this.restoreAnswer1Field.Text;
                string answer2  = this.restoreAnswer2Field.Text;
                if (deviceId.Length == 0 || (restoreQuestion2Label.Text.Length != 0 && answer1.Length == 0) || (restoreQuestion2Label.Text.Length != 0 && answer2.Length == 0))
                {
                    WinAuthForm.ErrorDialog(this.Owner, "Please enter the device ID and answers to your secret questions");
                    return(false);
                }

                try
                {
                    TrionAuthenticator authenticator = new TrionAuthenticator();
                    authenticator.Restore(email, password, deviceId, answer1, answer2);
                    this.Authenticator.AuthenticatorData = authenticator;
                }
                catch (InvalidRestoreResponseException irre)
                {
                    WinAuthForm.ErrorDialog(this.Owner, "Unable to restore the authenticator: " + irre.Message, irre);
                    return(false);
                }
                catch (Exception ex)
                {
                    WinAuthForm.ErrorDialog(this.Owner, "An error occured restoring the authenticator: " + ex.Message, ex);
                    return(false);
                }
            }

            return(true);
        }
        /// <summary>
        /// Verify and create the authenticator if needed
        /// </summary>
        /// <returns>true is successful</returns>
        private bool verifyAuthenticator()
        {
            if (this.tabControl1.SelectedIndex == 0)
            {
                if (this.Authenticator.AuthenticatorData == null)
                {
                    WinAuthForm.ErrorDialog(this.Owner, "您需要创建身份验证器并将其附加到您的帐户");
                    return(false);
                }
            }
            else
            {
                if (restoreQuestion1Label.Text.Length == 0)
                {
                    restoreGetQuestionsButton_Click(null, null);
                    return(false);
                }

                string email    = this.restoreEmailField.Text.Trim();
                string password = this.restorePasswordField.Text.Trim();
                string deviceId = this.restoreDeviceIdField.Text.Trim();
                string answer1  = this.restoreAnswer1Field.Text;
                string answer2  = this.restoreAnswer2Field.Text;
                if (deviceId.Length == 0 || (restoreQuestion2Label.Text.Length != 0 && answer1.Length == 0) || (restoreQuestion2Label.Text.Length != 0 && answer2.Length == 0))
                {
                    WinAuthForm.ErrorDialog(this.Owner, "请输入设备ID和您的安全问题的答案");
                    return(false);
                }

                try
                {
                    TrionAuthenticator authenticator = new TrionAuthenticator();
                    authenticator.Restore(email, password, deviceId, answer1, answer2);
                    this.Authenticator.AuthenticatorData = authenticator;
                }
                catch (InvalidRestoreResponseException irre)
                {
                    WinAuthForm.ErrorDialog(this.Owner, "无法恢复验证器: " + irre.Message, irre);
                    return(false);
                }
                catch (Exception ex)
                {
                    WinAuthForm.ErrorDialog(this.Owner, "发生恢复验证器的错误: " + ex.Message, ex);
                    return(false);
                }
            }

            return(true);
        }
		/// <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>
		/// Verify and create the authenticator if needed
		/// </summary>
		/// <returns>true is successful</returns>
		private bool verifyAuthenticator()
		{
			if (this.tabControl1.SelectedIndex == 0)
			{
				if (this.Authenticator.AuthenticatorData == null)
				{
					WinAuthForm.ErrorDialog(this.Owner, "You need to create an authenticator and attach it to your account");
					return false;
				}
			}
			else
			{				
				if (restoreQuestion1Label.Text.Length == 0)
				{
					restoreGetQuestionsButton_Click(null, null);
					return false;
				}

				string email = this.restoreEmailField.Text.Trim();
				string password = this.restorePasswordField.Text.Trim();
				string deviceId = this.restoreDeviceIdField.Text.Trim();
				string answer1 = this.restoreAnswer1Field.Text;
				string answer2 = this.restoreAnswer2Field.Text;
				if (deviceId.Length == 0 || (restoreQuestion2Label.Text.Length != 0 && answer1.Length == 0) || (restoreQuestion2Label.Text.Length != 0 && answer2.Length == 0))
				{
					WinAuthForm.ErrorDialog(this.Owner, "Please enter the device ID and answers to your secret questions");
					return false;
				}

				try
				{
					TrionAuthenticator authenticator = new TrionAuthenticator();
					authenticator.Restore(email, password, deviceId, answer1, answer2);
					this.Authenticator.AuthenticatorData = authenticator;
				}
				catch (InvalidRestoreResponseException irre)
				{
					WinAuthForm.ErrorDialog(this.Owner, "Unable to restore the authenticator: " + irre.Message, irre);
					return false;
				}
				catch (Exception ex)
				{
					WinAuthForm.ErrorDialog(this.Owner, "An error occured restoring the authenticator: " + ex.Message, ex);
					return false;
				}
			}

			return true;
		}