private void SetupTOTP_Load(object sender, EventArgs e) { GlobalWindowManager.AddWindow(this); Text = Localization.Strings.Setup + " - " + Localization.Strings.TrayTOTPPlugin; //Set form's name using constants. if (_plugin.TOTPEntryValidator.HasSeed(_entry)) //Checks the the totp settings exists. { string[] settings = _plugin.TOTPEntryValidator.SettingsGet(_entry); //Gets the the existing totp settings. bool validInterval; bool validLength; bool validUrl; _plugin.TOTPEntryValidator.SettingsValidate(_entry, out validInterval, out validLength, out validUrl); //Validates the settings value. if (validInterval) { NumericIntervalSetup.Value = Convert.ToDecimal(settings[0]); //Checks if interval is valid and sets interval numeric to the setting value. } if (validLength) //Checks if length is valid. { // Select the correct radio button RadioButtonLength6Setup.Checked = settings[1] == "6"; RadioButtonLength7Setup.Checked = settings[1] == "7"; RadioButtonLength8Setup.Checked = settings[1] == "8"; RadioButtonSteamFormatSetup.Checked = settings[1] == "S"; } if (validUrl) { ComboBoxTimeCorrectionSetup.Text = settings[2]; //Checks if url is valid and sets time correction textbox to the setting value. } DeleteSetupButton.Visible = true; //Shows the back button. HelpProviderSetup.SetHelpString(DeleteSetupButton, Localization.Strings.SetupDelete); } else { DeleteSetupButton.Visible = false; //Hides the back button. } if (_plugin.TOTPEntryValidator.HasSeed(_entry)) { TextBoxSeedSetup.Text = _plugin.TOTPEntryValidator.SeedGet(_entry).ReadString(); //Checks if the seed exists and sets seed textbox to the seed value. } ComboBoxTimeCorrectionSetup.Items.AddRange(_plugin.TimeCorrections.ToComboBox()); //Gets existings time corrections and adds them in the combobox. HelpProviderSetup.SetHelpString(FinishSetupButton, Localization.Strings.SetupFinish); ErrorProviderSetup.SetError(TextBoxSeedSetup, string.Empty); ErrorProviderSetup.SetError(NumericIntervalSetup, string.Empty); ErrorProviderSetup.SetError(RadioButtonLength8Setup, string.Empty); ErrorProviderSetup.SetError(ComboBoxTimeCorrectionSetup, string.Empty); }
private void SetupTOTP_Load(object sender, EventArgs e) { Text = TrayTOTP_Plugin_Localization.strSetup + TrayTOTP_Plugin_Localization.strSpaceDashSpace + TrayTOTP_Plugin_Localization.strTrayTOTPPlugin; //Set form's name using constants. if (_plugin.SettingsCheck(entry) || _plugin.SeedCheck(entry)) //Checks the the totp settings exists. { string[] Settings = _plugin.SettingsGet(entry); //Gets the the existing totp settings. bool ValidInterval = false; bool ValidLength = false; bool ValidUrl = false; _plugin.SettingsValidate(entry, out ValidInterval, out ValidLength, out ValidUrl); //Validates the settings value. if (ValidInterval) { NumericIntervalSetup.Value = Convert.ToDecimal(Settings[0]); //Checks if interval is valid and sets interval numeric to the setting value. } if (ValidLength) //Checks if length is valid. { RadioButtonLength6Setup.Checked = Settings[1] == "6"; //Sets length radio 6 to checked if the setting value is 6. RadioButtonLength8Setup.Checked = Settings[1] == "8"; //Sets length radio 8 to checked if the setting value is 8. RadioButtonSteamFormatSetup.Checked = Settings[1] == "S"; //Sets format Steam to checked if the setting value is S. } if (ValidUrl) { ComboBoxTimeCorrectionSetup.Text = Settings[2]; //Checks if url is valid and sets time correction textbox to the setting value. } DeleteSetupButton.Visible = true; //Shows the back button. HelpProviderSetup.SetHelpString(DeleteSetupButton, SetupTOTP_Localization.SetupDelete); } else { DeleteSetupButton.Visible = false; //Hides the back button. } if (_plugin.SeedCheck(entry)) { TextBoxSeedSetup.Text = _plugin.SeedGet(entry).ReadString(); //Checks if the seed exists and sets seed textbox to the seed value. } ComboBoxTimeCorrectionSetup.Items.AddRange(_plugin.TimeCorrections.ToComboBox()); //Gets existings time corrections and adds them in the combobox. HelpProviderSetup.SetHelpString(FinishSetupButton, SetupTOTP_Localization.SetupFinnish); ErrorProviderSetup.SetError(TextBoxSeedSetup, string.Empty); ErrorProviderSetup.SetError(NumericIntervalSetup, string.Empty); ErrorProviderSetup.SetError(RadioButtonLength8Setup, string.Empty); ErrorProviderSetup.SetError(ComboBoxTimeCorrectionSetup, string.Empty); }
/// <summary> /// Button that moves forward in the setup steps. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonFinish_Click(object sender, EventArgs e) { string InvalidBase32Chars; // TOTP Seed field if (TextBoxSeedSetup.Text == string.Empty) //If no TOTP Seed { ErrorProviderSetup.SetError(TextBoxSeedSetup, SetupTOTP_Localization.SetupSeedCantBeEmpty); } else if (!TextBoxSeedSetup.Text.ExtWithoutSpaces().ExtIsBase32(out InvalidBase32Chars)) // TODO: Add support to other known formats { ErrorProviderSetup.SetError(TextBoxSeedSetup, SetupTOTP_Localization.SetupInvalidCharacter + "(" + InvalidBase32Chars + ")!"); } else { ErrorProviderSetup.SetError(TextBoxSeedSetup, string.Empty); } // Interval field if ((NumericIntervalSetup.Value < 1) || (NumericIntervalSetup.Value > 60)) { ErrorProviderSetup.SetError(NumericIntervalSetup, string.Format(SetupTOTP_Localization.SetupInterval1to60, Environment.NewLine)); } else { ErrorProviderSetup.SetError(NumericIntervalSetup, string.Empty); } // Format/Interval radios if (!RadioButtonLength6Setup.Checked && !RadioButtonLength7Setup.Checked && !RadioButtonLength8Setup.Checked && !RadioButtonSteamFormatSetup.Checked) { ErrorProviderSetup.SetError(RadioButtonLength8Setup, SetupTOTP_Localization.SetupLengthMandatory); } else { ErrorProviderSetup.SetError(RadioButtonLength8Setup, string.Empty); } // Time Correction Field if (ComboBoxTimeCorrectionSetup.Text != string.Empty) { string uriName = ComboBoxTimeCorrectionSetup.Text; Uri uriResult; bool validURL = Uri.TryCreate(uriName, UriKind.Absolute, out uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); if (!validURL) { ErrorProviderSetup.SetError(ComboBoxTimeCorrectionSetup, SetupTOTP_Localization.SetupInvalidUrl); } else { ErrorProviderSetup.SetError(ComboBoxTimeCorrectionSetup, string.Empty); } } /* ErrorProviderSetup.SetError(ComboBoxTimeCorrectionSetup, SetupTOTP_Localization.SetupUrlMustContainHttp); * if (ComboBoxTimeCorrectionSetup.Text.Contains(";")) * ErrorProviderSetup.SetError(ComboBoxTimeCorrectionSetup, SetupTOTP_Localization.SetupInvalidCharacter + " (;)"); */ if (ErrorProviderSetup.GetError(TextBoxSeedSetup) != string.Empty || ErrorProviderSetup.GetError(NumericIntervalSetup) != string.Empty || ErrorProviderSetup.GetError(ComboBoxTimeCorrectionSetup) != string.Empty || ErrorProviderSetup.GetError(ComboBoxTimeCorrectionSetup) != string.Empty) { return; } try { entry.CreateBackup(_plugin.m_host.MainWindow.ActiveDatabase); entry.Strings.Set(_plugin.m_host.CustomConfig.GetString(KeeTrayTOTPExt.setname_string_TOTPSeed_StringName, TrayTOTP_Plugin_Localization.setdef_string_TOTPSeed_StringName), new ProtectedString(true, TextBoxSeedSetup.Text) ); string format = ""; if (RadioButtonLength6Setup.Checked) { format = "6"; } else if (RadioButtonLength7Setup.Checked) { format = "7"; } else if (RadioButtonLength8Setup.Checked) { format = "8"; } else if (RadioButtonSteamFormatSetup.Checked) { format = "S"; } entry.Strings.Set(_plugin.m_host.CustomConfig.GetString(KeeTrayTOTPExt.setname_string_TOTPSettings_StringName, TrayTOTP_Plugin_Localization.setdef_string_TOTPSettings_StringName), new ProtectedString(false, NumericIntervalSetup.Value.ToString() + ";" + format + (ComboBoxTimeCorrectionSetup.Text != string.Empty ? ";" : string.Empty) + ComboBoxTimeCorrectionSetup.Text) ); entry.Touch(true); _plugin.m_host.MainWindow.ActiveDatabase.Modified = true; } catch (Exception Ex) { MessageBox.Show(Ex.Message); return; } DialogResult = DialogResult.OK; Close(); }
/// <summary> /// Button that moves forward in the setup steps. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonFinish_Click(object sender, EventArgs e) { string invalidBase32Chars; // TOTP Seed field if (TextBoxSeedSetup.Text == string.Empty) //If no TOTP Seed { ErrorProviderSetup.SetError(TextBoxSeedSetup, Localization.Strings.SetupSeedCantBeEmpty); } else if (Base32.HasInvalidPadding(TextBoxSeedSetup.Text.ExtWithoutSpaces())) { ErrorProviderSetup.SetError(TextBoxSeedSetup, Localization.Strings.SetupInvalidPadding); } else if (!TextBoxSeedSetup.Text.ExtWithoutSpaces().IsBase32(out invalidBase32Chars)) { ErrorProviderSetup.SetError(TextBoxSeedSetup, Localization.Strings.SetupInvalidCharacter + "(" + invalidBase32Chars + ")"); } else { ErrorProviderSetup.SetError(TextBoxSeedSetup, string.Empty); } // Interval field if ((NumericIntervalSetup.Value < 1) || (NumericIntervalSetup.Value > 180)) { ErrorProviderSetup.SetError(NumericIntervalSetup, string.Format(Localization.Strings.SetupInterval, Environment.NewLine)); } else { ErrorProviderSetup.SetError(NumericIntervalSetup, string.Empty); } // Format/Interval radios if (!RadioButtonLength6Setup.Checked && !RadioButtonLength7Setup.Checked && !RadioButtonLength8Setup.Checked && !RadioButtonSteamFormatSetup.Checked) { ErrorProviderSetup.SetError(RadioButtonLength8Setup, Localization.Strings.SetupLengthMandatory); } else { ErrorProviderSetup.SetError(RadioButtonLength8Setup, string.Empty); } // Time Correction Field if (ComboBoxTimeCorrectionSetup.Text != string.Empty) { string uriName = ComboBoxTimeCorrectionSetup.Text; Uri uriResult; bool validUrl = Uri.TryCreate(uriName, UriKind.Absolute, out uriResult) && (uriResult.Scheme == Uri.UriSchemeHttp || uriResult.Scheme == Uri.UriSchemeHttps); if (!validUrl) { ErrorProviderSetup.SetError(ComboBoxTimeCorrectionSetup, Localization.Strings.SetupInvalidUrl); } else { ErrorProviderSetup.SetError(ComboBoxTimeCorrectionSetup, string.Empty); } } if (ErrorProviderSetup.GetError(TextBoxSeedSetup) != string.Empty || ErrorProviderSetup.GetError(NumericIntervalSetup) != string.Empty || ErrorProviderSetup.GetError(ComboBoxTimeCorrectionSetup) != string.Empty || ErrorProviderSetup.GetError(ComboBoxTimeCorrectionSetup) != string.Empty) { return; } try { _entry.CreateBackup(_plugin.PluginHost.MainWindow.ActiveDatabase); _entry.Strings.Set(_plugin.Settings.TOTPSeedStringName, new ProtectedString(true, TextBoxSeedSetup.Text)); string format = ""; if (RadioButtonLength6Setup.Checked) { format = "6"; } else if (RadioButtonLength7Setup.Checked) { format = "7"; } else if (RadioButtonLength8Setup.Checked) { format = "8"; } else if (RadioButtonSteamFormatSetup.Checked) { format = "S"; } var settings = new ProtectedString(false, NumericIntervalSetup.Value.ToString() + ";" + format + (ComboBoxTimeCorrectionSetup.Text != string.Empty ? ";" : string.Empty) + ComboBoxTimeCorrectionSetup.Text); _entry.Strings.Set(_plugin.Settings.TOTPSettingsStringName, settings); _entry.Touch(true); _plugin.PluginHost.MainWindow.ActiveDatabase.Modified = true; _plugin.ResetLastSelectedGroup(); } catch (Exception ex) { MessageBox.Show(ex.Message); return; } DialogResult = DialogResult.OK; Close(); }
/// <summary> /// Button that moves forward in the setup steps. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void ButtonNext_Click(object sender, EventArgs e) { switch (_CurrentStep) { case 1: //Welcome break; case 2: //Interval ErrorProviderSetup.SetError(NumericIntervalSetup, string.Empty); if ((NumericIntervalSetup.Value < 1) || (NumericIntervalSetup.Value > 60)) { ErrorProviderSetup.SetError(NumericIntervalSetup, string.Format(FormSetup_Localization.SetupInterval1to60, Environment.NewLine)); } if (ErrorProviderSetup.GetError(NumericIntervalSetup) != string.Empty) { return; } break; case 3: //Length ErrorProviderSetup.SetError(RadioButtonLength8Setup, string.Empty); if (!RadioButtonLength6Setup.Checked && !RadioButtonLength8Setup.Checked) { ErrorProviderSetup.SetError(RadioButtonLength8Setup, FormSetup_Localization.SetupLengthMandatory); } if (ErrorProviderSetup.GetError(RadioButtonLength8Setup) != string.Empty) { return; } break; case 4: //Seed ErrorProviderSetup.SetError(TextBoxSeedSetup, string.Empty); if (TextBoxSeedSetup.Text == string.Empty) { ErrorProviderSetup.SetError(TextBoxSeedSetup, FormSetup_Localization.SetupSeedCantBeEmpty); } string InvalidBase32Chars; if (!TextBoxSeedSetup.Text.ExtWithoutSpaces().ExtIsBase32(out InvalidBase32Chars)) { ErrorProviderSetup.SetError(TextBoxSeedSetup, FormSetup_Localization.SetupInvalidCharacter + "(" + InvalidBase32Chars + ")!"); } if (ErrorProviderSetup.GetError(TextBoxSeedSetup) != string.Empty) { return; } break; case 5: //Time Correction ErrorProviderSetup.SetError(ComboBoxTimeCorrectionSetup, string.Empty); if (ComboBoxTimeCorrectionSetup.Text != string.Empty && !ComboBoxTimeCorrectionSetup.Text.StartsWith("http")) { ErrorProviderSetup.SetError(ComboBoxTimeCorrectionSetup, FormSetup_Localization.SetupUrlMustContainHttp); } if (ComboBoxTimeCorrectionSetup.Text != string.Empty && !ComboBoxTimeCorrectionSetup.Text.Contains("://")) { ErrorProviderSetup.SetError(ComboBoxTimeCorrectionSetup, FormSetup_Localization.SetupInvalidUrl); } if (ComboBoxTimeCorrectionSetup.Text.Contains(";")) { ErrorProviderSetup.SetError(ComboBoxTimeCorrectionSetup, FormSetup_Localization.SetupInvalidCharacter + " (;)"); } if (ErrorProviderSetup.GetError(ComboBoxTimeCorrectionSetup) != string.Empty) { return; } break; case 6: //Proceed try { entry.CreateBackup(_plugin.m_host.MainWindow.ActiveDatabase); entry.Strings.Set(_plugin.m_host.CustomConfig.GetString(TrayTotpGTExt.setname_string_TotpSeed_StringName, TrayTotp_Plugin_Localization.setdef_string_TotpSeed_StringName), new ProtectedString(true, TextBoxSeedSetup.Text)); entry.Strings.Set(_plugin.m_host.CustomConfig.GetString(TrayTotpGTExt.setname_string_TotpSettings_StringName, TrayTotp_Plugin_Localization.setdef_string_TotpSettings_StringName), new ProtectedString(false, NumericIntervalSetup.Value.ToString() + ";" + (RadioButtonLength6Setup.Checked ? "6" : (RadioButtonLength8Setup.Checked ? "8" : "6")) + (ComboBoxTimeCorrectionSetup.Text != string.Empty ? ";" : string.Empty) + ComboBoxTimeCorrectionSetup.Text)); entry.Touch(true); _plugin.m_host.MainWindow.ActiveDatabase.Modified = true; } catch (Exception Ex) { MessageBox.Show(Ex.Message); return; } break; case 7: //Confirmation DialogResult = DialogResult.OK; Close(); break; } CurrentStep++; }