diff --git a/src/core/Entry.cpp b/src/core/Entry.cpp index 6ebc86421..3679ee71e 100644 --- a/src/core/Entry.cpp +++ b/src/core/Entry.cpp @@ -231,7 +231,7 @@ const QSharedPointer Entry::passwordHealth() const return m_data.passwordHealth; } -int Entry::getPasswordAgeInDays() const +int Entry::getPasswordAge() const { QListIterator i(m_history); i.toBack(); @@ -253,9 +253,9 @@ int Entry::getPasswordAgeInDays() const } if (!curr) { // If no change in history, password is from creation time - return this->timeInfo().creationTime().daysTo(QDateTime::currentDateTime()); + return this->timeInfo().creationTime().secsTo(QDateTime::currentDateTime()); } - return curr->timeInfo().lastModificationTime().daysTo(QDateTime::currentDateTime()); + return curr->timeInfo().lastModificationTime().secsTo(QDateTime::currentDateTime()); } bool Entry::excludeFromReports() const diff --git a/src/core/Entry.h b/src/core/Entry.h index 244dd63b4..1ac7c5763 100644 --- a/src/core/Entry.h +++ b/src/core/Entry.h @@ -116,7 +116,7 @@ public: QString path() const; const QSharedPointer passwordHealth(); const QSharedPointer passwordHealth() const; - int getPasswordAgeInDays() const; + int getPasswordAge() const; bool excludeFromReports() const; void setExcludeFromReports(bool state); diff --git a/src/core/PasswordHealth.cpp b/src/core/PasswordHealth.cpp index 1d23c8840..4556b1ebb 100644 --- a/src/core/PasswordHealth.cpp +++ b/src/core/PasswordHealth.cpp @@ -19,6 +19,7 @@ #include "Group.h" #include "PasswordHealth.h" +#include "Tools.h" #include "zxcvbn.h" namespace @@ -199,10 +200,12 @@ QSharedPointer 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) { - health->addScoreReason(QObject::tr("Password is %1 year(s) old", "", ageInYears).arg(ageInYears)); + int ageInSeconds = entry->getPasswordAge(); + // (365 days)(24 hours/day)(3600 s/hr) is approximately a year and gets compiled away. + // Unfortunately, Qt doesn't seem to have a utility for this. + if (ageInSeconds / (365 * 24 * 3600) > 1) { + Tools::humanReadableTimeDifference(ageInSeconds); + health->addScoreReason(QObject::tr("Password is %1 old").arg(Tools::humanReadableTimeDifference(ageInSeconds))); } // Return the result