/// <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 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 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++; }