add an option for randomizing the extension deadline

Proposed in Issue #6451
This commit is contained in:
Xavier Valls 2021-05-10 18:21:55 +02:00
parent 626f592c98
commit c669765256
3 changed files with 61 additions and 0 deletions

View File

@ -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<int>::of(&QSpinBox::valueChanged), this, [&](int n) {
m_daysRandomizeExtension = static_cast<qint64>(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);
}
});

View File

@ -165,6 +165,8 @@ private:
QSharedPointer<Database> m_db;
std::tuple<unsigned, TimeDelta> m_extensionOnPwUpdate;
qint64 m_daysRandomizeExtension;
bool m_create;
bool m_history;
#ifdef WITH_XC_SSHAGENT

View File

@ -336,6 +336,52 @@
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalRandomize">
<property name="spacing">
<number>1</number>
</property>
<property name="enabled">
<bool>false</bool>
</property>
<item>
<widget class="QCheckBox" name="randomizeExtensionDeadline">
<property name="toolTip">
<string>Toggle randomizing expiration date</string>
</property>
<property name="accessibleName">
<string>Toggle randomizing expiration date</string>
</property>
<property name="text">
<string>Randomize the extension deadline within the last </string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="randomizeByQuantity">
<property name="enabled">
<bool>false</bool>
</property>
<property name="minimum">
<number>0</number>
</property>
<property name="FixedWidth">
<number>5</number>
</property>
</widget>
</item>
<item>
<widget class="QLabel">
<property name="visible">
<bool>true</bool>
</property>
<property name="text">
<string> days</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
</item>