diff --git a/src/CMakeLists.txt b/src/CMakeLists.txt index 84cc6a48d..e9bbbc17e 100644 --- a/src/CMakeLists.txt +++ b/src/CMakeLists.txt @@ -104,6 +104,7 @@ set(keepassx_SOURCES gui/group/GroupView.cpp http/AccessControlDialog.cpp http/EntryConfig.cpp + http/HttpPasswordGeneratorWidget.cpp http/HttpSettings.cpp http/OptionDialog.cpp http/Protocol.cpp @@ -189,6 +190,7 @@ set(keepassx_MOC gui/group/GroupView.h http/AccessControlDialog.h http/EntryConfig.h + http/HttpPasswordGeneratorWidget.h http/OptionDialog.h http/Protocol.h http/Server.h @@ -221,6 +223,7 @@ set(keepassx_FORMS gui/entry/EditEntryWidgetMain.ui gui/group/EditGroupWidgetMain.ui http/AccessControlDialog.ui + http/HttpPasswordGeneratorWidget.ui http/OptionDialog.ui ) diff --git a/src/http/HttpPasswordGeneratorWidget.cpp b/src/http/HttpPasswordGeneratorWidget.cpp new file mode 100644 index 000000000..30e4f71e7 --- /dev/null +++ b/src/http/HttpPasswordGeneratorWidget.cpp @@ -0,0 +1,148 @@ +/* + * Copyright (C) 2013 Felix Geyer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#include "HttpPasswordGeneratorWidget.h" +#include "ui_HttpPasswordGeneratorWidget.h" + +#include + +#include "core/Config.h" +#include "core/PasswordGenerator.h" +#include "core/FilePath.h" + +HttpPasswordGeneratorWidget::HttpPasswordGeneratorWidget(QWidget* parent) + : QWidget(parent) + , m_updatingSpinBox(false) + , m_generator(new PasswordGenerator()) + , m_ui(new Ui::HttpPasswordGeneratorWidget()) +{ + m_ui->setupUi(this); + + connect(m_ui->buttonApply, SIGNAL(clicked()), SLOT(saveSettings())); + + connect(m_ui->sliderLength, SIGNAL(valueChanged(int)), SLOT(sliderMoved())); + connect(m_ui->spinBoxLength, SIGNAL(valueChanged(int)), SLOT(spinBoxChanged())); + + connect(m_ui->optionButtons, SIGNAL(buttonClicked(int)), SLOT(updateGenerator())); + m_ui->buttonApply->setEnabled(true); + + loadSettings(); + reset(); +} + +HttpPasswordGeneratorWidget::~HttpPasswordGeneratorWidget() +{ +} + +void HttpPasswordGeneratorWidget::loadSettings() +{ + m_ui->checkBoxLower->setChecked(config()->get("Http/generator/LowerCase", true).toBool()); + m_ui->checkBoxUpper->setChecked(config()->get("Http/generator/UpperCase", true).toBool()); + m_ui->checkBoxNumbers->setChecked(config()->get("Http/generator/Numbers", true).toBool()); + m_ui->checkBoxSpecialChars->setChecked(config()->get("Http/generator/SpecialChars", false).toBool()); + + m_ui->checkBoxExcludeAlike->setChecked(config()->get("Http/generator/ExcludeAlike", true).toBool()); + m_ui->checkBoxEnsureEvery->setChecked(config()->get("Http/generator/EnsureEvery", true).toBool()); + + m_ui->spinBoxLength->setValue(config()->get("Http/generator/Length", 16).toInt()); +} + +void HttpPasswordGeneratorWidget::saveSettings() +{ + config()->set("Http/generator/LowerCase", m_ui->checkBoxLower->isChecked()); + config()->set("Http/generator/UpperCase", m_ui->checkBoxUpper->isChecked()); + config()->set("Http/generator/Numbers", m_ui->checkBoxNumbers->isChecked()); + config()->set("Http/generator/SpecialChars", m_ui->checkBoxSpecialChars->isChecked()); + + config()->set("Http/generator/ExcludeAlike", m_ui->checkBoxExcludeAlike->isChecked()); + config()->set("Http/generator/EnsureEvery", m_ui->checkBoxEnsureEvery->isChecked()); + + config()->set("Http/generator/Length", m_ui->spinBoxLength->value()); +} + +void HttpPasswordGeneratorWidget::reset() +{ + updateGenerator(); +} + +void HttpPasswordGeneratorWidget::sliderMoved() +{ + if (m_updatingSpinBox) { + return; + } + + m_ui->spinBoxLength->setValue(m_ui->sliderLength->value()); + + updateGenerator(); +} + +void HttpPasswordGeneratorWidget::spinBoxChanged() +{ + // Interlock so that we don't update twice - this causes issues as the spinbox can go higher than slider + m_updatingSpinBox = true; + + m_ui->sliderLength->setValue(m_ui->spinBoxLength->value()); + + m_updatingSpinBox = false; + + updateGenerator(); +} + +PasswordGenerator::CharClasses HttpPasswordGeneratorWidget::charClasses() +{ + PasswordGenerator::CharClasses classes; + + if (m_ui->checkBoxLower->isChecked()) { + classes |= PasswordGenerator::LowerLetters; + } + + if (m_ui->checkBoxUpper->isChecked()) { + classes |= PasswordGenerator::UpperLetters; + } + + if (m_ui->checkBoxNumbers->isChecked()) { + classes |= PasswordGenerator::Numbers; + } + + if (m_ui->checkBoxSpecialChars->isChecked()) { + classes |= PasswordGenerator::SpecialCharacters; + } + + return classes; +} + +PasswordGenerator::GeneratorFlags HttpPasswordGeneratorWidget::generatorFlags() +{ + PasswordGenerator::GeneratorFlags flags; + + if (m_ui->checkBoxExcludeAlike->isChecked()) { + flags |= PasswordGenerator::ExcludeLookAlike; + } + + if (m_ui->checkBoxEnsureEvery->isChecked()) { + flags |= PasswordGenerator::CharFromEveryGroup; + } + + return flags; +} + +void HttpPasswordGeneratorWidget::updateGenerator() +{ + m_generator->setLength(m_ui->spinBoxLength->value()); + m_generator->setCharClasses(charClasses()); + m_generator->setFlags(generatorFlags()); +} diff --git a/src/http/HttpPasswordGeneratorWidget.h b/src/http/HttpPasswordGeneratorWidget.h new file mode 100644 index 000000000..5766a6e7f --- /dev/null +++ b/src/http/HttpPasswordGeneratorWidget.h @@ -0,0 +1,60 @@ +/* + * Copyright (C) 2013 Felix Geyer + * + * This program is free software: you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation, either version 2 or (at your option) + * version 3 of the License. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program. If not, see . + */ + +#ifndef KEEPASSX_PASSWORDGENERATORWIDGET_H +#define KEEPASSX_PASSWORDGENERATORWIDGET_H + +#include +#include + +#include "core/Global.h" +#include "core/PasswordGenerator.h" + +namespace Ui { + class HttpPasswordGeneratorWidget; +} + +class PasswordGenerator; + +class HttpPasswordGeneratorWidget : public QWidget +{ + Q_OBJECT + +public: + explicit HttpPasswordGeneratorWidget(QWidget* parent = Q_NULLPTR); + ~HttpPasswordGeneratorWidget(); + void loadSettings(); + void reset(); + +private Q_SLOTS: + void saveSettings(); + void sliderMoved(); + void spinBoxChanged(); + + void updateGenerator(); + +private: + bool m_updatingSpinBox; + + PasswordGenerator::CharClasses charClasses(); + PasswordGenerator::GeneratorFlags generatorFlags(); + + const QScopedPointer m_generator; + const QScopedPointer m_ui; +}; + +#endif // KEEPASSX_PASSWORDGENERATORWIDGET_H diff --git a/src/http/HttpPasswordGeneratorWidget.ui b/src/http/HttpPasswordGeneratorWidget.ui new file mode 100644 index 000000000..29399bcd6 --- /dev/null +++ b/src/http/HttpPasswordGeneratorWidget.ui @@ -0,0 +1,227 @@ + + + HttpPasswordGeneratorWidget + + + + 0 + 0 + 434 + 250 + + + + + + + + + + + + Length: + + + + + + + + + 1 + + + 64 + + + Qt::Horizontal + + + QSlider::TicksBelow + + + 8 + + + + + + + 1 + + + 999 + + + + + + + + + + + Character Types + + + + + + + + Upper Case Letters + + + A-Z + + + true + + + optionButtons + + + + + + + Lower Case Letters + + + a-z + + + true + + + optionButtons + + + + + + + Numbers + + + 0-9 + + + true + + + optionButtons + + + + + + + Special Characters + + + /*_& ... + + + true + + + optionButtons + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + Exclude look-alike characters + + + optionButtons + + + + + + + Ensure that the password contains characters from every group + + + optionButtons + + + + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + false + + + Accept + + + + + + + + + + PasswordComboBox + QComboBox +
gui/PasswordComboBox.h
+
+
+ + sliderLength + spinBoxLength + checkBoxUpper + checkBoxLower + checkBoxNumbers + checkBoxSpecialChars + checkBoxExcludeAlike + checkBoxEnsureEvery + buttonApply + + + + + + + false + + + +
diff --git a/src/http/HttpSettings.cpp b/src/http/HttpSettings.cpp index 15cd962bd..f98fcb7e2 100644 --- a/src/http/HttpSettings.cpp +++ b/src/http/HttpSettings.cpp @@ -14,6 +14,8 @@ #include "HttpSettings.h" #include "core/Config.h" +PasswordGenerator HttpSettings::m_generator; + bool HttpSettings::isEnabled() { return config()->get("Http/Enabled", true).toBool(); @@ -126,72 +128,73 @@ void HttpSettings::setSupportKphFields(bool supportKphFields) bool HttpSettings::passwordUseNumbers() { - return config()->get("Http/PasswordUseNumbers", true).toBool(); + return config()->get("Http/generator/Numbers", true).toBool(); } void HttpSettings::setPasswordUseNumbers(bool useNumbers) { - config()->set("Http/PasswordUseNumbers", useNumbers); + config()->set("Http/generator/Numbers", useNumbers); } bool HttpSettings::passwordUseLowercase() { - return config()->get("Http/PasswordUseLowercase", true).toBool(); + return config()->get("Http/generator/LowerCase", true).toBool(); } void HttpSettings::setPasswordUseLowercase(bool useLowercase) { - config()->set("Http/PasswordUseLowercase", useLowercase); + config()->set("Http/generator/LowerCase", useLowercase); } bool HttpSettings::passwordUseUppercase() { - return config()->get("Http/PasswordUseUppercase", true).toBool(); + return config()->get("Http/generator/UpperCase", true).toBool(); } void HttpSettings::setPasswordUseUppercase(bool useUppercase) { - config()->set("Http/PasswordUseUppercase", useUppercase); + config()->set("Http/generator/UpperCase", useUppercase); } bool HttpSettings::passwordUseSpecial() { - return config()->get("Http/PasswordUseSpecial", false).toBool(); + return config()->get("Http/generator/SpecialChars", false).toBool(); } void HttpSettings::setPasswordUseSpecial(bool useSpecial) { - config()->set("Http/PasswordUseSpecial", useSpecial); + config()->set("Http/generator/SpecialChars", useSpecial); } bool HttpSettings::passwordEveryGroup() { - return config()->get("Http/PasswordEveryGroup", true).toBool(); + return config()->get("Http/generator/EnsureEvery", true).toBool(); } void HttpSettings::setPasswordEveryGroup(bool everyGroup) { - config()->get("Http/PasswordEveryGroup", everyGroup); + config()->get("Http/generator/EnsureEvery", everyGroup); } bool HttpSettings::passwordExcludeAlike() { - return config()->get("Http/PasswordExcludeAlike", true).toBool(); + return config()->get("Http/generator/ExcludeAlike", true).toBool(); } void HttpSettings::setPasswordExcludeAlike(bool excludeAlike) { - config()->set("Http/PasswordExcludeAlike", excludeAlike); + config()->set("Http/generator/ExcludeAlike", excludeAlike); } int HttpSettings::passwordLength() { - return config()->get("Http/PasswordLength", 20).toInt(); + return config()->get("Http/generator/Length", 20).toInt(); } void HttpSettings::setPasswordLength(int length) { - config()->set("Http/PasswordLength", length); + config()->set("Http/generator/Length", length); + m_generator.setLength(length); } PasswordGenerator::CharClasses HttpSettings::passwordCharClasses() @@ -217,3 +220,12 @@ PasswordGenerator::GeneratorFlags HttpSettings::passwordGeneratorFlags() flags |= PasswordGenerator::CharFromEveryGroup; return flags; } + +QString HttpSettings::generatePassword() +{ + m_generator.setLength(passwordLength()); + m_generator.setCharClasses(passwordCharClasses()); + m_generator.setFlags(passwordGeneratorFlags()); + + return m_generator.generatePassword(); +} diff --git a/src/http/HttpSettings.h b/src/http/HttpSettings.h index 67a998eec..5f2577c39 100644 --- a/src/http/HttpSettings.h +++ b/src/http/HttpSettings.h @@ -59,6 +59,10 @@ public: static void setPasswordLength(int length); static PasswordGenerator::CharClasses passwordCharClasses(); static PasswordGenerator::GeneratorFlags passwordGeneratorFlags(); + static QString generatePassword(); + +private: + static PasswordGenerator m_generator; }; #endif // HTTPSETTINGS_H diff --git a/src/http/OptionDialog.cpp b/src/http/OptionDialog.cpp index 29ebeaa1a..63222947a 100644 --- a/src/http/OptionDialog.cpp +++ b/src/http/OptionDialog.cpp @@ -43,6 +43,7 @@ void OptionDialog::loadSettings() else ui->sortByTitle->setChecked(true); +/* ui->checkBoxLower->setChecked(settings.passwordUseLowercase()); ui->checkBoxNumbers->setChecked(settings.passwordUseNumbers()); ui->checkBoxUpper->setChecked(settings.passwordUseUppercase()); @@ -50,6 +51,7 @@ void OptionDialog::loadSettings() ui->checkBoxEnsureEvery->setChecked(settings.passwordEveryGroup()); ui->checkBoxExcludeAlike->setChecked(settings.passwordExcludeAlike()); ui->spinBoxLength->setValue(settings.passwordLength()); +*/ ui->alwaysAllowAccess->setChecked(settings.alwaysAllowAccess()); ui->alwaysAllowUpdate->setChecked(settings.alwaysAllowUpdate()); @@ -67,6 +69,7 @@ void OptionDialog::saveSettings() settings.setMatchUrlScheme(ui->matchUrlScheme->isChecked()); settings.setSortByUsername(ui->sortByUsername->isChecked()); +/* settings.setPasswordUseLowercase(ui->checkBoxLower->isChecked()); settings.setPasswordUseNumbers(ui->checkBoxNumbers->isChecked()); settings.setPasswordUseUppercase(ui->checkBoxUpper->isChecked()); @@ -74,6 +77,7 @@ void OptionDialog::saveSettings() settings.setPasswordEveryGroup(ui->checkBoxEnsureEvery->isChecked()); settings.setPasswordExcludeAlike(ui->checkBoxExcludeAlike->isChecked()); settings.setPasswordLength(ui->spinBoxLength->value()); +*/ settings.setAlwaysAllowAccess(ui->alwaysAllowAccess->isChecked()); settings.setAlwaysAllowUpdate(ui->alwaysAllowUpdate->isChecked()); diff --git a/src/http/OptionDialog.ui b/src/http/OptionDialog.ui index 621b94836..9563fd04a 100644 --- a/src/http/OptionDialog.ui +++ b/src/http/OptionDialog.ui @@ -114,88 +114,7 @@ Only entries with the same scheme (http://, https://, ftp://, ...) are returned< - - - - - - - Lower letters - - - - - - - Numbers - - - - - - - Upper letters - - - - - - - Special characters - - - - - - - - - - - Ensure that the password contains characters from every group - - - - - - - Exclude look-alike characters - - - - - - - - - Length: - - - - - - - 1 - - - 999 - - - - - - - Qt::Horizontal - - - - 40 - 20 - - - - - + @@ -300,6 +219,19 @@ Only entries with the same scheme (http://, https://, ftp://, ...) are returned< + + + HttpPasswordGeneratorWidget + QWidget +
http/HttpPasswordGeneratorWidget.h
+ 1 +
+ + PasswordEdit + QLineEdit +
gui/PasswordEdit.h
+
+
diff --git a/src/http/Service.cpp b/src/http/Service.cpp index 9daf9c018..525b28778 100644 --- a/src/http/Service.cpp +++ b/src/http/Service.cpp @@ -494,7 +494,7 @@ void Service::updateEntry(const QString &, const QString &uuid, const QString &l QString Service::generatePassword() { - return QString("nonrandompassword"); + return HttpSettings::generatePassword(); } void Service::removeSharedEncryptionKeys()