From 37b18a532ced883d1f95636fb24016b603cc2835 Mon Sep 17 00:00:00 2001 From: Jonathan White Date: Tue, 19 Mar 2019 08:25:30 -0400 Subject: [PATCH] Allow database creation without password * The warning about not having a password is now properly shown (previously it did not let you continue at all) * General cleanup of the master key editing workflow --- .../DatabaseSettingsWidgetMasterKey.cpp | 20 +++++++++---------- src/gui/masterkey/PasswordEditWidget.cpp | 15 ++++++++------ src/gui/masterkey/PasswordEditWidget.h | 1 + 3 files changed, 20 insertions(+), 16 deletions(-) diff --git a/src/gui/dbsettings/DatabaseSettingsWidgetMasterKey.cpp b/src/gui/dbsettings/DatabaseSettingsWidgetMasterKey.cpp index a8cff2c6d..d1a64b529 100644 --- a/src/gui/dbsettings/DatabaseSettingsWidgetMasterKey.cpp +++ b/src/gui/dbsettings/DatabaseSettingsWidgetMasterKey.cpp @@ -136,34 +136,34 @@ bool DatabaseSettingsWidgetMasterKey::save() auto newKey = QSharedPointer::create(); - QSharedPointer passwordKey; - QSharedPointer fileKey; - QSharedPointer ykCrKey; + QSharedPointer oldPasswordKey; + QSharedPointer oldFileKey; + QSharedPointer oldChallengeResponse; for (const auto& key : m_db->key()->keys()) { if (key->uuid() == PasswordKey::UUID) { - passwordKey = key; + oldPasswordKey = key; } else if (key->uuid() == FileKey::UUID) { - fileKey = key; + oldFileKey = key; } } for (const auto& key : m_db->key()->challengeResponseKeys()) { if (key->uuid() == YkChallengeResponseKey::UUID) { - ykCrKey = key; + oldChallengeResponse = key; } } - if (!addToCompositeKey(m_passwordEditWidget, newKey, passwordKey)) { + if (!addToCompositeKey(m_passwordEditWidget, newKey, oldPasswordKey)) { return false; } - if (!addToCompositeKey(m_keyFileEditWidget, newKey, fileKey)) { + if (!addToCompositeKey(m_keyFileEditWidget, newKey, oldFileKey)) { return false; } #ifdef WITH_XC_YUBIKEY - if (!addToCompositeKey(m_yubiKeyEditWidget, newKey, ykCrKey)) { + if (!addToCompositeKey(m_yubiKeyEditWidget, newKey, oldChallengeResponse)) { return false; } #endif @@ -177,7 +177,7 @@ bool DatabaseSettingsWidgetMasterKey::save() return false; } - if (m_passwordEditWidget->visiblePage() == KeyComponentWidget::AddNew) { + if (m_passwordEditWidget->isEmpty()) { auto answer = MessageBox::warning(this, tr("No password set"), tr("WARNING! You have not set a password. Using a database without " diff --git a/src/gui/masterkey/PasswordEditWidget.cpp b/src/gui/masterkey/PasswordEditWidget.cpp index d9d293c43..6f85bb198 100644 --- a/src/gui/masterkey/PasswordEditWidget.cpp +++ b/src/gui/masterkey/PasswordEditWidget.cpp @@ -40,7 +40,10 @@ PasswordEditWidget::~PasswordEditWidget() bool PasswordEditWidget::addToCompositeKey(QSharedPointer key) { - key->addKey(QSharedPointer::create(m_compUi->enterPasswordEdit->text())); + QString pw = m_compUi->enterPasswordEdit->text(); + if (!pw.isEmpty()) { + key->addKey(QSharedPointer::create(pw)); + } return true; } @@ -60,6 +63,11 @@ bool PasswordEditWidget::isPasswordVisible() const return m_compUi->togglePasswordButton->isChecked(); } +bool PasswordEditWidget::isEmpty() const +{ + return m_compUi->enterPasswordEdit->text().isEmpty(); +} + QWidget* PasswordEditWidget::componentEditWidget() { m_compEditWidget = new QWidget(); @@ -86,11 +94,6 @@ void PasswordEditWidget::initComponentEditWidget(QWidget* widget) bool PasswordEditWidget::validate(QString& errorMessage) const { - if (m_compUi->enterPasswordEdit->text().isEmpty()) { - errorMessage = tr("Password cannot be empty."); - return false; - } - if (m_compUi->enterPasswordEdit->text() != m_compUi->repeatPasswordEdit->text()) { errorMessage = tr("Passwords do not match."); return false; diff --git a/src/gui/masterkey/PasswordEditWidget.h b/src/gui/masterkey/PasswordEditWidget.h index eefe8855e..9f3eb75ce 100644 --- a/src/gui/masterkey/PasswordEditWidget.h +++ b/src/gui/masterkey/PasswordEditWidget.h @@ -38,6 +38,7 @@ public: bool addToCompositeKey(QSharedPointer key) override; void setPasswordVisible(bool visible); bool isPasswordVisible() const; + bool isEmpty() const; bool validate(QString& errorMessage) const override; protected: