mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-05-03 15:15:02 -04:00
First pass at adding age penalty to health check
This commit is contained in:
parent
033dd79c58
commit
9055fb307d
3 changed files with 37 additions and 0 deletions
|
@ -231,6 +231,33 @@ const QSharedPointer<PasswordHealth> Entry::passwordHealth() const
|
|||
return m_data.passwordHealth;
|
||||
}
|
||||
|
||||
int Entry::getPasswordAgeInDays() const
|
||||
{
|
||||
QListIterator<Entry*> i(m_history);
|
||||
i.toBack();
|
||||
Entry* compare = nullptr;
|
||||
Entry* curr = nullptr;
|
||||
|
||||
while (i.hasPrevious()) {
|
||||
curr = i.previous();
|
||||
if (!compare) {
|
||||
compare = curr;
|
||||
continue;
|
||||
}
|
||||
if (*curr->attributes() != *compare->attributes()) {
|
||||
if (curr->password() != compare->password()) {
|
||||
// Found most recent password change; break out.
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
if (!curr) {
|
||||
// If no change in history, password is from creation time
|
||||
return this->timeInfo().creationTime().daysTo(QDateTime::currentDateTime());
|
||||
}
|
||||
return curr->timeInfo().lastModificationTime().daysTo(QDateTime::currentDateTime());
|
||||
}
|
||||
|
||||
bool Entry::excludeFromReports() const
|
||||
{
|
||||
return m_data.excludeFromReports
|
||||
|
|
|
@ -116,6 +116,7 @@ public:
|
|||
QString path() const;
|
||||
const QSharedPointer<PasswordHealth> passwordHealth();
|
||||
const QSharedPointer<PasswordHealth> passwordHealth() const;
|
||||
int getPasswordAgeInDays() const;
|
||||
bool excludeFromReports() const;
|
||||
void setExcludeFromReports(bool state);
|
||||
|
||||
|
|
|
@ -198,6 +198,15 @@ QSharedPointer<PasswordHealth> HealthChecker::evaluate(const Entry* entry) const
|
|||
}
|
||||
}
|
||||
|
||||
// Fourth, reduce score by 5 for each year beyond one year old.
|
||||
int age = entry->getPasswordAgeInDays();
|
||||
int ageInYears = age / 365;
|
||||
if (ageInYears > 1) {
|
||||
constexpr auto penalty = 5;
|
||||
health->adjustScore(-penalty * ageInYears);
|
||||
health->addScoreReason(QObject::tr("Password is %1 year(s) old", "", ageInYears).arg(ageInYears));
|
||||
}
|
||||
|
||||
// Return the result
|
||||
return health;
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue