SettingsCheck() private method

Check if specified Entry contains Settings that are not null.
private SettingsCheck ( PwEntry pe ) : bool
pe PwEntry Pasword Entry.
return bool
        /// <summary>
        /// Tells KeePass what to display in the column.
        /// </summary>
        /// <param name="columnName"></param>
        /// <param name="pe"></param>
        /// <returns>String displayed in the columns.</returns>
        public override string GetCellData(string columnName, PwEntry pe)
        {
            if (columnName == null)
            {
                throw new ArgumentNullException("columnName");
            }

            if (pe == null)
            {
                throw new ArgumentNullException("pe");
            }

            if (_plugin.SettingsCheck(pe) && _plugin.SeedCheck(pe))
            {
                bool validInterval;
                bool validLength;
                bool validUrl;
                if (_plugin.SettingsValidate(pe, out validInterval, out validLength, out validUrl))
                {
                    string[] settings = _plugin.SettingsGet(pe);

                    TOTPProvider totpGenerator = new TOTPProvider(settings, ref _plugin.TimeCorrections);

                    if (_plugin.SeedValidate(pe))
                    {
                        return(totpGenerator.GenerateByByte(Base32.Decode(_plugin.SeedGet(pe).ReadString().ExtWithoutSpaces())) + (_pluginHost.CustomConfig.GetBool(KeeTrayTOTPExt.setname_bool_TOTPColumnTimer_Visible, true) ? totpGenerator.Timer.ToString().ExtWithParenthesis().ExtWithSpaceBefore() : string.Empty));
                    }
                    return(Localization.Strings.ErrorBadSeed);
                }
                return(Localization.Strings.ErrorBadSettings);
            }
            return(_plugin.SettingsCheck(pe) || _plugin.SeedCheck(pe) ? Localization.Strings.ErrorStorage : string.Empty);
        }
            /// <summary>
            /// Tells KeePass what to display in the column.
            /// </summary>
            /// <param name="strColumnName"></param>
            /// <param name="pe"></param>
            /// <returns>String displayed in the columns.</returns>
            public override string GetCellData(string strColumnName, PwEntry pe)
            {
                if (strColumnName == null)
                {
                    throw new ArgumentNullException("strColumnName");
                }
                if (pe == null)
                {
                    throw new ArgumentNullException("pe");
                }
                if (plugin.SettingsCheck(pe) && plugin.SeedCheck(pe))
                {
                    bool ValidInterval;
                    bool ValidLength;
                    bool ValidUrl;
                    if (plugin.SettingsValidate(pe, out ValidInterval, out ValidLength, out ValidUrl))
                    {
                        string[] Settings = plugin.SettingsGet(pe);

                        TOTPProvider TOTPGenerator = new TOTPProvider(Settings, ref plugin.TimeCorrections);

                        if (plugin.SeedValidate(pe))
                        {
                            return(TOTPGenerator.GenerateByByte(
                                       Base32.Decode(plugin.SeedGet(pe).ReadString().ExtWithoutSpaces())) + (m_host.CustomConfig.GetBool(setname_bool_TOTPColumnTimer_Visible, true) ? TOTPGenerator.Timer.ToString().ExtWithParenthesis().ExtWithSpaceBefore() : string.Empty));
                        }
                        return(TrayTOTP_CustomColumn_Localization.strWarningBadSeed);
                    }
                    return(TrayTOTP_CustomColumn_Localization.strWarningBadSet);
                }
                return(plugin.SettingsCheck(pe) || plugin.SeedCheck(pe) ? TrayTOTP_CustomColumn_Localization.strWarningStorage : string.Empty);
            }
 /// <summary>
 /// Windows Form Load.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void FormTimeCorrection_Load(object sender, EventArgs e)
 {
     Text = TrayTOTP_Plugin_Localization.strTimeCorrection + TrayTOTP_Plugin_Localization.strSpaceDashSpace + TrayTOTP_Plugin_Localization.strTrayTOTPPlugin; //Sets the form's display text.
     if (plugin.m_host.MainWindow.ActiveDatabase.IsOpen)
     {
         foreach (var pe in plugin.m_host.MainWindow.ActiveDatabase.RootGroup.GetEntries(true))                                     //Goes through all entries to find existing urls but excludes existing time corrections.
         {
             if (plugin.SettingsCheck(pe))                                                                                          //Checks that settings exists for this entry.
             {
                 string[] Settings = plugin.SettingsGet(pe);                                                                        //Gets the entry's totp settings.
                 bool     ValidInterval = false; bool ValidLength = false; bool ValidUrl = false;
                 if (plugin.SettingsValidate(pe, out ValidInterval, out ValidLength, out ValidUrl))                                 //Validates the settings.
                 {
                     if (ValidUrl)                                                                                                  //Makes sure the URL is also valid.
                     {
                         if (!ComboBoxUrlTimeCorrection.Items.Contains(Settings[2]) && plugin.TimeCorrections[Settings[2]] == null) //Checks if not already in combobox or is an existing time correction.
                         {
                             ComboBoxUrlTimeCorrection.Items.Add(Settings[2]);                                                      //Adds the URL to the combobox for quick adding.
                         }
                     }
                 }
             }
         }
     }
 }
Beispiel #4
0
        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.SettingsCheck(_entry) || _plugin.SeedCheck(_entry))                  //Checks the the totp settings exists.
            {
                string[] settings = _plugin.SettingsGet(_entry);                             //Gets the the existing totp settings.
                bool     validInterval;
                bool     validLength;
                bool     validUrl;
                _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.
                {
                    // 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.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, Localization.Strings.SetupFinish);

            ErrorProviderSetup.SetError(TextBoxSeedSetup, string.Empty);
            ErrorProviderSetup.SetError(NumericIntervalSetup, string.Empty);
            ErrorProviderSetup.SetError(RadioButtonLength8Setup, string.Empty);
            ErrorProviderSetup.SetError(ComboBoxTimeCorrectionSetup, string.Empty);
        }
Beispiel #5
0
        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);
        }
Beispiel #6
0
        /// <summary>
        /// Windows Form Load.
        /// </summary>
        /// <param name="sender"></param>
        /// <param name="e"></param>
        private void FormTimeCorrection_Load(object sender, EventArgs e)
        {
            GlobalWindowManager.AddWindow(this);

            Text = Localization.Strings.TimeCorrection + " - " + Localization.Strings.TrayTOTPPlugin;
            if (_plugin.PluginHost.MainWindow.ActiveDatabase.IsOpen)
            {
                foreach (var pe in _plugin.PluginHost.MainWindow.ActiveDatabase.RootGroup.GetEntries(true))
                {
                    if (_plugin.SettingsCheck(pe))
                    {
                        string[] settings = _plugin.SettingsGet(pe);
                        bool     validUrl;
                        if (_plugin.SettingsValidate(pe, out validUrl) && validUrl && !ComboBoxUrlTimeCorrection.Items.Contains(settings[2]) && _plugin.TimeCorrections[settings[2]] == null)
                        {
                            ComboBoxUrlTimeCorrection.Items.Add(settings[2]);
                        }
                    }
                }
            }
        }