diff --git a/src/gui/dbsettings/DatabaseSettingsWidgetDatabaseKey.cpp b/src/gui/dbsettings/DatabaseSettingsWidgetDatabaseKey.cpp index 58531539bf..055f3d41bf 100644 --- a/src/gui/dbsettings/DatabaseSettingsWidgetDatabaseKey.cpp +++ b/src/gui/dbsettings/DatabaseSettingsWidgetDatabaseKey.cpp @@ -177,18 +177,16 @@ bool DatabaseSettingsWidgetDatabaseKey::save() // Show warning if database password is weak if (!m_passwordEditWidget->isEmpty() && m_passwordEditWidget->getPasswordQuality() < PasswordHealth::Quality::Good) { - QScopedPointer msgBox(new QMessageBox(this)); - msgBox->setIcon(QMessageBox::Warning); - msgBox->setWindowTitle(tr("Weak password")); - msgBox->setText(tr("WARNING! You have set a weak password. If you do not choose a stronger and " - "more complex password, your database may be compromised more easily.\n\n" - "Are you sure you want to continue using a weak password?")); - auto btn = msgBox->addButton(tr("Continue"), QMessageBox::ButtonRole::AcceptRole); - msgBox->addButton(QMessageBox::Cancel); - msgBox->setDefaultButton(QMessageBox::Cancel); - msgBox->exec(); - - if (msgBox->clickedButton() != btn) { + auto dialogResult = + MessageBox::warning(this, + tr("Weak password"), + tr("WARNING! You have set a weak password. If you do not choose a stronger and " + "more complex password, your database may be compromised more easily.\n\n" + "Are you sure you want to continue using a weak password?"), + MessageBox::Continue | MessageBox::Cancel, + MessageBox::Cancel); + + if (dialogResult == MessageBox::Cancel) { return false; } } diff --git a/tests/gui/TestGui.cpp b/tests/gui/TestGui.cpp index f7307276c4..ca0b7ef7d9 100644 --- a/tests/gui/TestGui.cpp +++ b/tests/gui/TestGui.cpp @@ -257,9 +257,9 @@ void TestGui::testCreateDatabase() passwordWidget->findChild("repeatPasswordEdit")->findChild("passwordEdit"); QTRY_VERIFY(passwordEdit->isVisible()); QTRY_VERIFY(passwordEdit->hasFocus()); - QTest::keyClicks(passwordEdit, "Xi3R0nW9PWapNjj"); + QTest::keyClicks(passwordEdit, "test"); QTest::keyClick(passwordEdit, Qt::Key::Key_Tab); - QTest::keyClicks(passwordRepeatEdit, "Xi3R0nW9PWapNjj"); + QTest::keyClicks(passwordRepeatEdit, "test"); // add key file auto* additionalOptionsButton = wizard->currentPage()->findChild("additionalKeyOptionsToggle"); @@ -286,7 +286,10 @@ void TestGui::testCreateDatabase() tmpFile.close(); fileDialog()->setNextFileName(tmpFile.fileName()); + // click Continue on the warning due to weak password + MessageBox::setNextAnswer(MessageBox::Continue); QTest::keyClick(fileEdit, Qt::Key::Key_Enter); + tmpFile.remove();); triggerAction("actionDatabaseNew"); @@ -309,7 +312,7 @@ void TestGui::testCreateDatabase() QCOMPARE(m_db->kdf()->uuid(), KeePass2::KDF_ARGON2D); QCOMPARE(m_db->cipher(), KeePass2::CIPHER_AES256); auto compositeKey = QSharedPointer::create(); - compositeKey->addKey(QSharedPointer::create("Xi3R0nW9PWapNjj")); + compositeKey->addKey(QSharedPointer::create("test")); auto fileKey = QSharedPointer::create(); fileKey->load(QString("%1/%2").arg(QString(KEEPASSX_TEST_DATA_DIR), "FileKeyHashed.key")); compositeKey->addKey(fileKey);