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
This commit is contained in:
Jonathan White 2019-03-19 08:25:30 -04:00
parent e20d652cca
commit 37b18a532c
3 changed files with 20 additions and 16 deletions

View File

@ -136,34 +136,34 @@ bool DatabaseSettingsWidgetMasterKey::save()
auto newKey = QSharedPointer<CompositeKey>::create();
QSharedPointer<Key> passwordKey;
QSharedPointer<Key> fileKey;
QSharedPointer<ChallengeResponseKey> ykCrKey;
QSharedPointer<Key> oldPasswordKey;
QSharedPointer<Key> oldFileKey;
QSharedPointer<ChallengeResponseKey> 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 "

View File

@ -40,7 +40,10 @@ PasswordEditWidget::~PasswordEditWidget()
bool PasswordEditWidget::addToCompositeKey(QSharedPointer<CompositeKey> key)
{
key->addKey(QSharedPointer<PasswordKey>::create(m_compUi->enterPasswordEdit->text()));
QString pw = m_compUi->enterPasswordEdit->text();
if (!pw.isEmpty()) {
key->addKey(QSharedPointer<PasswordKey>::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;

View File

@ -38,6 +38,7 @@ public:
bool addToCompositeKey(QSharedPointer<CompositeKey> key) override;
void setPasswordVisible(bool visible);
bool isPasswordVisible() const;
bool isEmpty() const;
bool validate(QString& errorMessage) const override;
protected: