From c669765256381cd38fd2847e4c3a2c86d6bee667 Mon Sep 17 00:00:00 2001 From: Xavier Valls Date: Mon, 10 May 2021 18:21:55 +0200 Subject: [PATCH] add an option for randomizing the extension deadline Proposed in Issue #6451 --- src/gui/entry/EditEntryWidget.cpp | 13 ++++++++ src/gui/entry/EditEntryWidget.h | 2 ++ src/gui/entry/EditEntryWidgetMain.ui | 46 ++++++++++++++++++++++++++++ 3 files changed, 61 insertions(+) diff --git a/src/gui/entry/EditEntryWidget.cpp b/src/gui/entry/EditEntryWidget.cpp index 8f8aa3301..38c59d91e 100644 --- a/src/gui/entry/EditEntryWidget.cpp +++ b/src/gui/entry/EditEntryWidget.cpp @@ -200,12 +200,25 @@ void EditEntryWidget::setupMain() connect(m_mainUi->autoExtendExpire, &QCheckBox::toggled, [&](bool enabled) { m_mainUi->extendByQuantity->setEnabled(enabled); m_mainUi->extendByMagnitude->setEnabled(enabled); + m_mainUi->randomizeExtensionDeadline->setEnabled(enabled); + }); + + connect(m_mainUi->randomizeExtensionDeadline, &QCheckBox::toggled, [&](bool enabled) { + m_mainUi->randomizeByQuantity->setEnabled(enabled); + }); + + connect(m_mainUi->randomizeByQuantity, QOverload::of(&QSpinBox::valueChanged), this, [&](int n) { + m_daysRandomizeExtension = static_cast(n); }); connect(m_mainUi->passwordEdit, &QLineEdit::textChanged, this, [&]() { if (m_mainUi->autoExtendExpire->isEnabled()) { TimeDelta delta = std::get<1>(m_extensionOnPwUpdate) * std::get<0>(m_extensionOnPwUpdate); QDateTime now = Clock::currentDateTime(); QDateTime expiryDateTime = now + delta; + if (m_mainUi->randomizeExtensionDeadline->isEnabled()) { + expiryDateTime = + expiryDateTime.addDays(-QRandomGenerator::global()->bounded(0, m_daysRandomizeExtension)); + } m_mainUi->expireDatePicker->setDateTime(expiryDateTime); } }); diff --git a/src/gui/entry/EditEntryWidget.h b/src/gui/entry/EditEntryWidget.h index af212acb3..8ad27462f 100644 --- a/src/gui/entry/EditEntryWidget.h +++ b/src/gui/entry/EditEntryWidget.h @@ -165,6 +165,8 @@ private: QSharedPointer m_db; std::tuple m_extensionOnPwUpdate; + qint64 m_daysRandomizeExtension; + bool m_create; bool m_history; #ifdef WITH_XC_SSHAGENT diff --git a/src/gui/entry/EditEntryWidgetMain.ui b/src/gui/entry/EditEntryWidgetMain.ui index 74e80d019..7eee2a2d3 100644 --- a/src/gui/entry/EditEntryWidgetMain.ui +++ b/src/gui/entry/EditEntryWidgetMain.ui @@ -336,6 +336,52 @@ + + + + 1 + + + false + + + + + Toggle randomizing expiration date + + + Toggle randomizing expiration date + + + Randomize the extension deadline within the last + + + + + + + false + + + 0 + + + 5 + + + + + + + true + + + days + + + + +