keepassxc icon indicating copy to clipboard operation
keepassxc copied to clipboard

Add predefined search for TOTP entries

Open Copilot opened this issue 8 months ago • 3 comments

This PR implements a predefined search to find all TOTP entries, addressing the feature request for a dedicated OTP page similar to Google Authenticator.

Changes Made

Core Functionality

  • Added is:totp search support in EntrySearcher that leverages the existing Entry::hasTotp() method
  • Added "TOTP Entries" predefined search in TagModel following the same pattern as existing searches like "Expired" and "Weak Passwords"

Implementation Details

The implementation follows the established patterns in the codebase:

// EntrySearcher now supports case-insensitive TOTP search
} else if (term.word.compare("totp", Qt::CaseInsensitive) == 0) {
    found = entry->hasTotp();
    break;
}

// TagModel includes new predefined search
<< qMakePair(tr("TOTP Entries"), QString("is:totp"));

User Experience

Users can now:

  • Select "TOTP Entries" from the predefined searches in the left sidebar
  • Use is:totp search query directly in the search bar
  • Use !is:totp to exclude TOTP entries from results
  • Case-insensitive search (is:TOTP works the same as is:totp)

Testing

Added comprehensive test coverage in TestEntrySearcher::testTotpSearch() that validates:

  • Positive matching (entries with TOTP are found)
  • Negative matching (entries without TOTP are excluded)
  • Case-insensitive search functionality
  • Exclusion operator support

Code Quality

  • Minimal changes: Only 4 lines of production code added
  • Follows existing patterns: Uses the same structure as is:expired and is:weak searches
  • Translatable: Uses tr() function for internationalization
  • Well-tested: Includes focused unit tests

This provides users with the requested dedicated view for TOTP entries, making it easy to manage two-factor authentication codes within KeePassXC.

Fixes #9362.


💬 Share your feedback on Copilot coding agent for the chance to win a $200 gift card! Click here to start the survey.

Copilot avatar Jun 15 '25 15:06 Copilot

Change this from is:totp to has:totp. This will require you to introduce a new "has" prefix for EntrySearcher.

droidmonkey avatar Jun 15 '25 15:06 droidmonkey

Change this from is:totp to has:totp. This will require you to introduce a new "has" prefix for EntrySearcher.

Done. Changed from is:totp to has:totp and introduced the new "has" prefix for EntrySearcher. The implementation adds a new Field::Has enum value and moves the TOTP search logic to the new case while maintaining the existing "is" prefix for other searches like "expired" and "weak". All tests and predefined searches have been updated accordingly. Commit: a9a4176

[!WARNING]

Firewall rules blocked me from connecting to one or more addresses

I tried to connect to the following addresses, but was blocked by firewall rules:

  • 224.0.0.251
  • esm.ubuntu.com
    • Triggering command: /usr/lib/apt/methods/https (dns block)

If you need me to access, download, or install something from one of these locations, you can either:

Copilot avatar Jun 15 '25 15:06 Copilot

Codecov Report

:x: Patch coverage is 77.77778% with 2 lines in your changes missing coverage. Please review. :white_check_mark: Project coverage is 63.87%. Comparing base (3c7c3b0) to head (8773d49). :warning: Report is 67 commits behind head on develop.

Files with missing lines Patch % Lines
src/core/EntrySearcher.cpp 71.43% 2 Missing :warning:
Additional details and impacted files
@@             Coverage Diff             @@
##           develop   #12199      +/-   ##
===========================================
- Coverage    63.87%   63.87%   -0.00%     
===========================================
  Files          369      369              
  Lines        38935    38943       +8     
===========================================
+ Hits         24866    24871       +5     
- Misses       14069    14072       +3     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

:rocket: New features to boost your workflow:
  • :snowflake: Test Analytics: Detect flaky tests, report on failures, and find test suite problems.
  • :package: JS Bundle Analysis: Save yourself from yourself by tracking and limiting bundle sizes in JS merges.

codecov[bot] avatar Jun 15 '25 16:06 codecov[bot]