Skip to content

Commit

Permalink
Show entry in Health Check if expires within a month
Browse files Browse the repository at this point in the history
Reduce score more and more (=move entry up in Health Check)
as the expiry date approaches.

Fixes #551
  • Loading branch information
wolframroesler committed Jan 4, 2020
1 parent a8b42e3 commit 3c38bd5
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Binary file modified share/demo.kdbx
Binary file not shown.
23 changes: 23 additions & 0 deletions src/core/PasswordHealth.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -104,12 +104,35 @@ PasswordHealth::PasswordHealth(QSharedPointer<Database> db, QString pwd, Cache*
PasswordHealth::PasswordHealth(QSharedPointer<Database> db, const Entry& entry, Cache* cache)
: PasswordHealth(db, entry.password(), cache)
{
// If the password has already expired, reduce score to 0.
// Else, if the password is going to expire in the next
// 30 days, reduce score by 2 points per day.
if (entry.isExpired()) {
m_score = 0;
addTo(m_reason, QApplication::tr("Password has expired"));
addTo(m_details,
QApplication::tr("Password expiry was %1")
.arg(entry.timeInfo().expiryTime().toString(Qt::DefaultLocaleShortDate)));
} else if (entry.timeInfo().expires()) {
const auto days = QDateTime::currentDateTime().daysTo(entry.timeInfo().expiryTime());
if (days <= 30) {
// First bring the score down into the "weak" range
// so that the entry appears in Health Check. Then
// reduce the score by 2 points for every day that
// we get closer to expiry. days<=0 has already
// been handled above ("isExpired()").
if (m_score > 60) {
m_score = 60;
}
m_score -= (30 - days) * 2;
addTo(m_reason,
days <= 2 ? QApplication::tr("Password is about to expire")
: days <= 10 ? QApplication::tr("Password expires in %1 days").arg(days)
: QApplication::tr("Password will expire soon"));
addTo(m_details,
QApplication::tr("Password expires on %1")
.arg(entry.timeInfo().expiryTime().toString(Qt::DefaultLocaleShortDate)));
}
}
}

Expand Down

0 comments on commit 3c38bd5

Please sign in to comment.