diff --git a/share/translations/keepassxc_en.ts b/share/translations/keepassxc_en.ts index c48214215..ced96cab5 100644 --- a/share/translations/keepassxc_en.ts +++ b/share/translations/keepassxc_en.ts @@ -6888,6 +6888,14 @@ Do you want to overwrite it? Special Characters + + passwordLength + + + + Characters: %1 + + PasswordWidget diff --git a/src/gui/PasswordGeneratorWidget.cpp b/src/gui/PasswordGeneratorWidget.cpp index 084efa60f..c1e82974e 100644 --- a/src/gui/PasswordGeneratorWidget.cpp +++ b/src/gui/PasswordGeneratorWidget.cpp @@ -57,6 +57,7 @@ PasswordGeneratorWidget::PasswordGeneratorWidget(QWidget* parent) connect(m_ui->editNewPassword, SIGNAL(textChanged(QString)), SLOT(updateButtonsEnabled(QString))); connect(m_ui->editNewPassword, SIGNAL(textChanged(QString)), SLOT(updatePasswordStrength())); + connect(m_ui->editNewPassword, SIGNAL(textChanged(QString)), SLOT(updatePasswordLengthLabel(QString))); connect(m_ui->buttonAdvancedMode, SIGNAL(toggled(bool)), SLOT(setAdvancedMode(bool))); connect(m_ui->buttonAddHex, SIGNAL(clicked()), SLOT(excludeHexChars())); connect(m_ui->editAdditionalChars, SIGNAL(textChanged(QString)), SLOT(updateGenerator())); @@ -80,7 +81,7 @@ PasswordGeneratorWidget::PasswordGeneratorWidget(QWidget* parent) connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(updateGenerator())); connect(m_ui->wordCaseComboBox, SIGNAL(currentIndexChanged(int)), SLOT(updateGenerator())); - // set font size of password quality and entropy labels dynamically to 80% of + // set font size of password quality, characters, and entropy labels dynamically to 80% of // the default font size, but make it no smaller than 8pt QFont defaultFont; auto smallerSize = static_cast(defaultFont.pointSize() * 0.8f); @@ -88,6 +89,7 @@ PasswordGeneratorWidget::PasswordGeneratorWidget(QWidget* parent) defaultFont.setPointSize(smallerSize); m_ui->entropyLabel->setFont(defaultFont); m_ui->strengthLabel->setFont(defaultFont); + m_ui->passwordLengthLabel->setFont(defaultFont); } // set default separator to Space @@ -316,6 +318,11 @@ void PasswordGeneratorWidget::updatePasswordStrength() } } +void PasswordGeneratorWidget::updatePasswordLengthLabel(const QString& password) +{ + m_ui->passwordLengthLabel->setText(tr("Characters: %1").arg(QString::number(password.length()))); +} + void PasswordGeneratorWidget::applyPassword() { saveSettings(); diff --git a/src/gui/PasswordGeneratorWidget.h b/src/gui/PasswordGeneratorWidget.h index 2257cbf08..2f92a3eca 100644 --- a/src/gui/PasswordGeneratorWidget.h +++ b/src/gui/PasswordGeneratorWidget.h @@ -76,6 +76,7 @@ protected: private slots: void updateButtonsEnabled(const QString& password); void updatePasswordStrength(); + void updatePasswordLengthLabel(const QString& password); void setAdvancedMode(bool advanced); void excludeHexChars(); diff --git a/src/gui/PasswordGeneratorWidget.ui b/src/gui/PasswordGeneratorWidget.ui index 250f13038..9c06847e6 100644 --- a/src/gui/PasswordGeneratorWidget.ui +++ b/src/gui/PasswordGeneratorWidget.ui @@ -7,7 +7,7 @@ 0 0 729 - 427 + 433 @@ -59,6 +59,50 @@ + + + + + 0 + 0 + + + + + 70 + 0 + + + + + 16777215 + 30 + + + + passwordLength + + + Qt::AlignRight|Qt::AlignTop|Qt::AlignTrailing + + + 3 + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index da06fad42..694fbf36c 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -895,6 +895,7 @@ void TestGui::testPasswordEntryEntropy() pwGeneratorWidget->findChild("editNewPassword")->findChild("passwordEdit"); auto* entropyLabel = pwGeneratorWidget->findChild("entropyLabel"); auto* strengthLabel = pwGeneratorWidget->findChild("strengthLabel"); + auto* passwordLengthLabel = pwGeneratorWidget->findChild("passwordLengthLabel"); QFETCH(QString, password); QFETCH(QString, expectedStrengthLabel); @@ -902,10 +903,12 @@ void TestGui::testPasswordEntryEntropy() // Dynamically calculate entropy due to variances with zxcvbn wordlists PasswordHealth health(password); auto expectedEntropy = QString("Entropy: %1 bit").arg(QString::number(health.entropy(), 'f', 2)); + auto expectedPasswordLength = QString("Characters: %1").arg(QString::number(password.length())); generatedPassword->setText(password); QCOMPARE(entropyLabel->text(), expectedEntropy); QCOMPARE(strengthLabel->text(), expectedStrengthLabel); + QCOMPARE(passwordLengthLabel->text(), expectedPasswordLength); QTest::mouseClick(generatedPassword, Qt::LeftButton); QTest::keyClick(generatedPassword, Qt::Key_Escape););