Пример #1
0
 /// <summary>
 /// Windows Form Load.
 /// </summary>
 /// <param name="sender"></param>
 /// <param name="e"></param>
 private void FormSetup_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))                                                                                                               //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.
         }
         if (ValidUrl)
         {
             ComboBoxTimeCorrectionSetup.Text = Settings[2];           //Checks if url is valid and sets time correction textbox to the setting value.
         }
     }
     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.
     CurrentStep = 1;                                                                  //Initial step.
 }
 /// <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);
             var      TotpGenerator = new Totp_Provider(Convert.ToInt16(Settings[0]), Convert.ToInt16(Settings[1]));
             if (ValidUrl)
             {
                 var TimeCorrection = plugin.TimeCorrections[Settings[2]];
                 if (TimeCorrection == null)
                 {
                     return(TrayTotp_CustomColumn_Localization.strWarningBadUrl);
                 }
                 TotpGenerator.TimeCorrection = TimeCorrection.TimeCorrection;
             }
             if (plugin.SeedValidate(pe))
             {
                 return(TotpGenerator.Generate(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);
 }