Skip to content

Commit 5652102

Browse files
Support TIMEOTP autotype and entry placeholder (#13117)
* Additional fix for #7263 to support KeePass2 placeholder for TOTP --------- Co-authored-by: Janek Bevendorff <janek@keepassxc.org>
1 parent fd10c9d commit 5652102

File tree

4 files changed

+25
-3
lines changed

4 files changed

+25
-3
lines changed

src/autotype/AutoType.cpp

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -645,7 +645,7 @@ AutoType::parseSequence(const QString& entrySequence, const Entry* entry, QStrin
645645
} else if (placeholder == "clearfield") {
646646
// Platform-specific field clearing
647647
actions << QSharedPointer<AutoTypeClearField>::create();
648-
} else if (placeholder == "totp") {
648+
} else if (placeholder == "totp" || placeholder == "timeotp") {
649649
if (entry->hasValidTotp()) {
650650
// Calculate TOTP at the time of typing including delays
651651
bool isValid = false;

src/core/Entry.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1594,6 +1594,7 @@ Entry::PlaceholderType Entry::placeholderType(const QString& placeholder) const
15941594
{QStringLiteral("{PASSWORD}"), PlaceholderType::Password},
15951595
{QStringLiteral("{NOTES}"), PlaceholderType::Notes},
15961596
{QStringLiteral("{TOTP}"), PlaceholderType::Totp},
1597+
{QStringLiteral("{TIMEOTP}"), PlaceholderType::Totp},
15971598
{QStringLiteral("{URL}"), PlaceholderType::Url},
15981599
{QStringLiteral("{UUID}"), PlaceholderType::Uuid},
15991600
{QStringLiteral("{URL:RMVSCM}"), PlaceholderType::UrlWithoutScheme},

tests/TestAutoType.cpp

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
#include "TestAutoType.h"
2020

2121
#include <QPluginLoader>
22+
#include <QRegularExpression>
2223
#include <QTest>
2324

2425
#include "autotype/AutoType.h"
@@ -475,7 +476,7 @@ void TestAutoType::testAutoTypeEmptyWindowAssociation()
475476
QVERIFY(assoc.isEmpty());
476477
}
477478

478-
void TestAutoType::testAutoTypeTotpDelay()
479+
void TestAutoType::testAutoTypeTotp()
479480
{
480481
// Get the TOTP time step in milliseconds
481482
auto totpStep = m_entry1->totpSettings()->step * 1000;
@@ -494,4 +495,24 @@ void TestAutoType::testAutoTypeTotpDelay()
494495
QString("Typed TOTP (%1) should differ from current TOTP (%2) due to delay")
495496
.arg(totpParts[0], totpParts[1])
496497
.toLatin1());
498+
499+
m_test->clearActions();
500+
501+
// Test TIMEOTP placeholder (KeePass2 Compatibility)
502+
m_autoType->performAutoTypeWithSequence(m_entry1, "{TIMEOTP}");
503+
typedChars = m_test->actionChars();
504+
QCOMPARE(typedChars.size(), m_entry1->totpSettings()->digits);
505+
// Verify that the typedchars are all numbers
506+
QRegularExpression re("^\\d+$");
507+
QVERIFY(re.match(typedChars).hasMatch());
508+
509+
m_test->clearActions();
510+
511+
// Test that TIMEOTP also works as an entry placeholder
512+
m_entry1->setPassword("{TIMEOTP}");
513+
m_autoType->performAutoTypeWithSequence(m_entry1, "{PASSWORD}");
514+
typedChars = m_test->actionChars();
515+
QCOMPARE(typedChars.size(), m_entry1->totpSettings()->digits);
516+
// Verify that the typedchars are all numbers
517+
QVERIFY(re.match(typedChars).hasMatch());
497518
}

tests/TestAutoType.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ private slots:
5252
void testAutoTypeSyntaxChecks();
5353
void testAutoTypeEffectiveSequences();
5454
void testAutoTypeEmptyWindowAssociation();
55-
void testAutoTypeTotpDelay();
55+
void testAutoTypeTotp();
5656

5757
private:
5858
AutoTypePlatformInterface* m_platform;

0 commit comments

Comments
 (0)