Add filter for showing all password in health report

This commit is contained in:
shotor 2025-03-08 02:05:02 +01:00
parent 33a3796074
commit d9b780b47b
4 changed files with 36 additions and 11 deletions

View file

@ -47,21 +47,28 @@ PasswordHealth::PasswordHealth(const QString& pwd)
void PasswordHealth::init(double entropy)
{
m_score = m_entropy = entropy;
m_scoreDetails << QObject::tr("Password entropy is %1 bits").arg(QString::number(m_entropy, 'f', 2));
switch (quality()) {
case Quality::Excellent:
m_scoreReasons << QObject::tr("Excellent password");
break;
case Quality::Good:
m_scoreReasons << QObject::tr("Good password");
break;
case Quality::Bad:
case Quality::Poor:
m_scoreReasons << QObject::tr("Very weak password");
m_scoreDetails << QObject::tr("Password entropy is %1 bits").arg(QString::number(m_entropy, 'f', 2));
break;
case Quality::Weak:
m_scoreReasons << QObject::tr("Weak password");
m_scoreDetails << QObject::tr("Password entropy is %1 bits").arg(QString::number(m_entropy, 'f', 2));
break;
default:
// No reason or details for good and excellent passwords
// should never happen
break;
}
}

View file

@ -124,10 +124,7 @@ Health::Health(QSharedPointer<Database> db)
m_anyExcludedEntries = true;
}
// Add entry if its password isn't at least "good"
if (item->health->quality() < PasswordHealth::Quality::Good) {
m_items.append(item);
}
m_items.append(item);
}
}
@ -154,6 +151,7 @@ ReportsWidgetHealthcheck::ReportsWidgetHealthcheck(QWidget* parent)
connect(m_ui->healthcheckTableView, SIGNAL(doubleClicked(QModelIndex)), SLOT(emitEntryActivated(QModelIndex)));
connect(m_ui->showExcluded, SIGNAL(stateChanged(int)), this, SLOT(calculateHealth()));
connect(m_ui->showExpired, SIGNAL(stateChanged(int)), this, SLOT(calculateHealth()));
connect(m_ui->showWeakOnly, SIGNAL(stateChanged(int)), this, SLOT(calculateHealth()));
new QShortcut(Qt::Key_Delete, this, SLOT(deleteSelectedEntries()));
}
@ -267,6 +265,16 @@ void ReportsWidgetHealthcheck::calculateHealth()
continue;
}
if (m_ui->showWeakOnly->isChecked()) {
switch (item->entry->passwordHealth()->quality()) {
case PasswordHealth::Quality::Good:
case PasswordHealth::Quality::Excellent:
continue;
default:
break;
}
}
// Show the entry in the report
addHealthRow(item->health, item->group, item->entry, item->exclude);
}

View file

@ -54,6 +54,16 @@
</attribute>
</widget>
</item>
<item>
<widget class="QCheckBox" name="showWeakOnly">
<property name="text">
<string>Show weak passwords only</string>
</property>
<property name="checked">
<bool>true</bool>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="showExpired">
<property name="text">

View file

@ -54,13 +54,13 @@ void TestPasswordHealth::testNoDb()
QCOMPARE(good.score(), 78);
QCOMPARE(int(good.entropy()), 78);
QCOMPARE(good.quality(), PasswordHealth::Quality::Good);
QVERIFY(good.scoreReason().isEmpty());
QVERIFY(good.scoreDetails().isEmpty());
QVERIFY(!good.scoreReason().isEmpty());
QVERIFY(!good.scoreDetails().isEmpty());
const auto excellent = PasswordHealth("prompter-ream-oversleep-step-extortion-quarrel-reflected-prefix");
QCOMPARE(excellent.score(), 164);
QCOMPARE(int(excellent.entropy()), 164);
QCOMPARE(excellent.quality(), PasswordHealth::Quality::Excellent);
QVERIFY(excellent.scoreReason().isEmpty());
QVERIFY(excellent.scoreDetails().isEmpty());
QVERIFY(!excellent.scoreReason().isEmpty());
QVERIFY(!excellent.scoreDetails().isEmpty());
}