Skip to content

Commit

Permalink
Use MessageBox instead of QMessageBox for the weak password warning
Browse files Browse the repository at this point in the history
  • Loading branch information
egglessness committed Nov 6, 2023
1 parent dabd295 commit 6072f9c
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 15 deletions.
22 changes: 10 additions & 12 deletions src/gui/dbsettings/DatabaseSettingsWidgetDatabaseKey.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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<QMessageBox> 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;
}
}
Expand Down
9 changes: 6 additions & 3 deletions tests/gui/TestGui.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -257,9 +257,9 @@ void TestGui::testCreateDatabase()
passwordWidget->findChild<PasswordWidget*>("repeatPasswordEdit")->findChild<QLineEdit*>("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<QPushButton*>("additionalKeyOptionsToggle");
Expand All @@ -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");
Expand All @@ -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<CompositeKey>::create();
compositeKey->addKey(QSharedPointer<PasswordKey>::create("Xi3R0nW9PWapNjj"));
compositeKey->addKey(QSharedPointer<PasswordKey>::create("test"));
auto fileKey = QSharedPointer<FileKey>::create();
fileKey->load(QString("%1/%2").arg(QString(KEEPASSX_TEST_DATA_DIR), "FileKeyHashed.key"));
compositeKey->addKey(fileKey);
Expand Down

0 comments on commit 6072f9c

Please sign in to comment.