diff --git a/src/browser/BrowserSettings.cpp b/src/browser/BrowserSettings.cpp index 8e83d7933c..b889a678e9 100644 --- a/src/browser/BrowserSettings.cpp +++ b/src/browser/BrowserSettings.cpp @@ -531,7 +531,7 @@ QJsonObject BrowserSettings::generatePassword() m_passwordGenerator.setCharClasses(passwordCharClasses()); m_passwordGenerator.setFlags(passwordGeneratorFlags()); const QString pw = m_passwordGenerator.generatePassword(); - password["entropy"] = PasswordHealth(nullptr, pw).entropy(); + password["entropy"] = PasswordHealth(pw).entropy(); password["password"] = pw; } else { m_passPhraseGenerator.setWordCount(passPhraseWordCount()); diff --git a/src/cli/Estimate.cpp b/src/cli/Estimate.cpp index a97b72fc4a..3b75090571 100644 --- a/src/cli/Estimate.cpp +++ b/src/cli/Estimate.cpp @@ -52,7 +52,7 @@ static void estimate(const char* pwd, bool advanced) int len = static_cast(strlen(pwd)); if (!advanced) { - const auto e = PasswordHealth(nullptr, pwd).entropy(); + const auto e = PasswordHealth(pwd).entropy(); // clang-format off out << QObject::tr("Length %1").arg(len, 0) << '\t' << QObject::tr("Entropy %1").arg(e, 0, 'f', 3) << '\t' diff --git a/src/core/PasswordHealth.cpp b/src/core/PasswordHealth.cpp index 78159cc919..a448eee8c3 100644 --- a/src/core/PasswordHealth.cpp +++ b/src/core/PasswordHealth.cpp @@ -48,6 +48,11 @@ PasswordHealth::PasswordHealth(double entropy) } } +PasswordHealth::PasswordHealth(QString pwd) + : PasswordHealth(ZxcvbnMatch(pwd.toLatin1(), nullptr, nullptr)) +{ +} + PasswordHealth::PasswordHealth(QSharedPointer db, QString pwd, Cache* cache) : PasswordHealth(ZxcvbnMatch(pwd.toLatin1(), nullptr, nullptr)) { diff --git a/src/core/PasswordHealth.h b/src/core/PasswordHealth.h index a6d486b6b3..a7bc775c81 100644 --- a/src/core/PasswordHealth.h +++ b/src/core/PasswordHealth.h @@ -41,6 +41,7 @@ class PasswordHealth */ PasswordHealth() = default; explicit PasswordHealth(double entropy); + explicit PasswordHealth(QString pwd); PasswordHealth(QSharedPointer db, QString pwd, Cache* cache = nullptr); PasswordHealth(QSharedPointer db, const Entry& entry, Cache* cache = nullptr); diff --git a/src/gui/PasswordGeneratorWidget.cpp b/src/gui/PasswordGeneratorWidget.cpp index d554f2f70f..d7da06a815 100644 --- a/src/gui/PasswordGeneratorWidget.cpp +++ b/src/gui/PasswordGeneratorWidget.cpp @@ -264,7 +264,7 @@ void PasswordGeneratorWidget::updatePasswordStrength(const QString& password) { PasswordHealth health; if (m_ui->tabWidget->currentIndex() == Password) { - health = PasswordHealth(nullptr, password); + health = PasswordHealth(password); } else { health = PasswordHealth(m_dicewareGenerator->estimateEntropy()); } diff --git a/tests/TestPasswordHealth.cpp b/tests/TestPasswordHealth.cpp index 1f864f8e3e..ff92571987 100644 --- a/tests/TestPasswordHealth.cpp +++ b/tests/TestPasswordHealth.cpp @@ -28,7 +28,7 @@ void TestPasswordHealth::initTestCase() void TestPasswordHealth::testNoDb() { - const auto empty = PasswordHealth(nullptr, ""); + const auto empty = PasswordHealth(""); QCOMPARE(empty.score(), 0); QCOMPARE(empty.entropy(), 0.0); QCOMPARE(empty.quality(), PasswordHealth::Quality::bad); @@ -36,7 +36,7 @@ void TestPasswordHealth::testNoDb() QVERIFY(!empty.reason().isEmpty()); QVERIFY(!empty.details().isEmpty()); - const auto poor = PasswordHealth(nullptr, "secret"); + const auto poor = PasswordHealth("secret"); QCOMPARE(poor.score(), 6); QCOMPARE(int(poor.entropy()), 6); QCOMPARE(poor.quality(), PasswordHealth::Quality::poor); @@ -44,7 +44,7 @@ void TestPasswordHealth::testNoDb() QVERIFY(!poor.reason().isEmpty()); QVERIFY(!poor.details().isEmpty()); - const auto weak = PasswordHealth(nullptr, "Yohb2ChR4"); + const auto weak = PasswordHealth("Yohb2ChR4"); QCOMPARE(weak.score(), 47); QCOMPARE(int(weak.entropy()), 47); QCOMPARE(weak.quality(), PasswordHealth::Quality::weak); @@ -52,7 +52,7 @@ void TestPasswordHealth::testNoDb() QVERIFY(!weak.reason().isEmpty()); QVERIFY(!weak.details().isEmpty()); - const auto good = PasswordHealth(nullptr, "MIhIN9UKrgtPL2hp"); + const auto good = PasswordHealth("MIhIN9UKrgtPL2hp"); QCOMPARE(good.score(), 78); QCOMPARE(int(good.entropy()), 78); QCOMPARE(good.quality(), PasswordHealth::Quality::good); @@ -60,7 +60,7 @@ void TestPasswordHealth::testNoDb() QVERIFY(good.reason().isEmpty()); QVERIFY(good.details().isEmpty()); - const auto excellent = PasswordHealth(nullptr, "prompter-ream-oversleep-step-extortion-quarrel-reflected-prefix"); + 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);