/// <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> /// Auto-Type Function. /// </summary> /// <param name="sender"></param> /// <param name="e"></param> private void SprEngine_FilterCompile(object sender, SprEventArgs e) { if ((e.Context.Flags & SprCompileFlags.ExtActive) == SprCompileFlags.ExtActive) { if (e.Text.IndexOf(m_host.CustomConfig.GetString(setname_string_AutoType_FieldName, setdef_string_AutoType_FieldName).ExtWithBrackets(), StringComparison.InvariantCultureIgnoreCase) >= 0) { if (SettingsCheck(e.Context.Entry) && SeedCheck(e.Context.Entry)) { bool ValidInterval = false; bool ValidLength = false; bool ValidUrl = false; if (SettingsValidate(e.Context.Entry, out ValidInterval, out ValidLength, out ValidUrl)) { string[] Settings = SettingsGet(e.Context.Entry); TOTPProvider TOTPGenerator = new TOTPProvider(Settings, ref this.TimeCorrections); string InvalidCharacters; if (SeedValidate(e.Context.Entry, out InvalidCharacters)) { e.Context.Entry.Touch(false); string totp = TOTPGenerator.GenerateByByte(Base32.Decode(SeedGet(e.Context.Entry).ReadString().ExtWithoutSpaces())); e.Text = StrUtil.ReplaceCaseInsensitive(e.Text, m_host.CustomConfig.GetString(setname_string_AutoType_FieldName,setdef_string_AutoType_FieldName).ExtWithBrackets(), totp); } else { e.Text = string.Empty; MessageService.ShowWarning(TrayTOTP_Plugin_Localization.strWarningBadSeed + InvalidCharacters.ExtWithParenthesis().ExtWithSpaceBefore()); } if (TOTPGenerator.TimeCorrectionError) MessageService.ShowWarning(TrayTOTP_Plugin_Localization.strWarningBadUrl); } else { e.Text = string.Empty; MessageService.ShowWarning(TrayTOTP_Plugin_Localization.strWarningBadSet); } } else { e.Text = string.Empty; MessageService.ShowWarning(TrayTOTP_Plugin_Localization.strWarningNotSet); } } } }