Database key settings: fix UI bug

Fix a bug in the database key settings dialog, where it was previously
always incorrectly applying an empty password if the password was not
changed but some other change was made (e.g. adding or removing a key
file).
This commit is contained in:
Carlo Teubner 2024-06-28 23:01:34 +01:00 committed by Jonathan White
parent 0a516d526c
commit 854459068f
2 changed files with 5 additions and 3 deletions

View File

@ -62,7 +62,7 @@ bool PasswordEditWidget::isPasswordVisible() const
bool PasswordEditWidget::isEmpty() const
{
return visiblePage() != Page::Edit || m_compUi->enterPasswordEdit->text().isEmpty();
return m_compUi->enterPasswordEdit->text().isEmpty();
}
PasswordHealth::Quality PasswordEditWidget::getPasswordQuality() const

View File

@ -160,7 +160,9 @@ bool DatabaseSettingsWidgetDatabaseKey::saveSettings()
}
// Show warning if database password has not been set
if (m_passwordEditWidget->visiblePage() == KeyComponentWidget::Page::AddNew || m_passwordEditWidget->isEmpty()) {
if (m_passwordEditWidget->visiblePage() == KeyComponentWidget::Page::AddNew
|| (m_passwordEditWidget->visiblePage() == KeyComponentWidget::Page::Edit && m_passwordEditWidget->isEmpty())) {
QScopedPointer<QMessageBox> msgBox(new QMessageBox(this));
msgBox->setIcon(QMessageBox::Warning);
msgBox->setWindowTitle(tr("No password set"));
@ -179,7 +181,7 @@ bool DatabaseSettingsWidgetDatabaseKey::saveSettings()
return false;
}
if (!m_passwordEditWidget->isEmpty()) {
if (m_passwordEditWidget->visiblePage() == KeyComponentWidget::Page::Edit && !m_passwordEditWidget->isEmpty()) {
// Prevent setting password with a quality less than the minimum required
auto minQuality = qBound(0, config()->get(Config::Security_DatabasePasswordMinimumQuality).toInt(), 4);
if (m_passwordEditWidget->getPasswordQuality() < static_cast<PasswordHealth::Quality>(minQuality)) {