Fixed password generation for keepasshttp

This commit is contained in:
Keith Bennett 2014-03-22 22:07:43 +00:00
parent b87097a7ab
commit 75564c8fb5
9 changed files with 487 additions and 97 deletions

View File

@ -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
)

View File

@ -0,0 +1,148 @@
/*
* Copyright (C) 2013 Felix Geyer <debfx@fobos.de>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#include "HttpPasswordGeneratorWidget.h"
#include "ui_HttpPasswordGeneratorWidget.h"
#include <QLineEdit>
#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());
}

View File

@ -0,0 +1,60 @@
/*
* Copyright (C) 2013 Felix Geyer <debfx@fobos.de>
*
* 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 <http://www.gnu.org/licenses/>.
*/
#ifndef KEEPASSX_PASSWORDGENERATORWIDGET_H
#define KEEPASSX_PASSWORDGENERATORWIDGET_H
#include <QWidget>
#include <QComboBox>
#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<PasswordGenerator> m_generator;
const QScopedPointer<Ui::HttpPasswordGeneratorWidget> m_ui;
};
#endif // KEEPASSX_PASSWORDGENERATORWIDGET_H

View File

@ -0,0 +1,227 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>HttpPasswordGeneratorWidget</class>
<widget class="QWidget" name="HttpPasswordGeneratorWidget">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>434</width>
<height>250</height>
</rect>
</property>
<property name="windowTitle">
<string/>
</property>
<layout class="QVBoxLayout" name="verticalLayout_2">
<item>
<layout class="QGridLayout" name="gridLayout">
<item row="1" column="0">
<widget class="QLabel" name="labelLength">
<property name="text">
<string>Length:</string>
</property>
</widget>
</item>
<item row="1" column="1">
<layout class="QHBoxLayout" name="horizontalLayout_4">
<item>
<widget class="QSlider" name="sliderLength">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>64</number>
</property>
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="tickPosition">
<enum>QSlider::TicksBelow</enum>
</property>
<property name="tickInterval">
<number>8</number>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxLength">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>999</number>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QGroupBox" name="groupBox">
<property name="title">
<string>Character Types</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout_5">
<item>
<widget class="QToolButton" name="checkBoxUpper">
<property name="toolTip">
<string>Upper Case Letters</string>
</property>
<property name="text">
<string>A-Z</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">optionButtons</string>
</attribute>
</widget>
</item>
<item>
<widget class="QToolButton" name="checkBoxLower">
<property name="toolTip">
<string>Lower Case Letters</string>
</property>
<property name="text">
<string>a-z</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">optionButtons</string>
</attribute>
</widget>
</item>
<item>
<widget class="QToolButton" name="checkBoxNumbers">
<property name="toolTip">
<string>Numbers</string>
</property>
<property name="text">
<string>0-9</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">optionButtons</string>
</attribute>
</widget>
</item>
<item>
<widget class="QToolButton" name="checkBoxSpecialChars">
<property name="toolTip">
<string>Special Characters</string>
</property>
<property name="text">
<string>/*_&amp; ...</string>
</property>
<property name="checkable">
<bool>true</bool>
</property>
<attribute name="buttonGroup">
<string notr="true">optionButtons</string>
</attribute>
</widget>
</item>
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBoxExcludeAlike">
<property name="text">
<string>Exclude look-alike characters</string>
</property>
<attribute name="buttonGroup">
<string notr="true">optionButtons</string>
</attribute>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxEnsureEvery">
<property name="text">
<string>Ensure that the password contains characters from every group</string>
</property>
<attribute name="buttonGroup">
<string notr="true">optionButtons</string>
</attribute>
</widget>
</item>
</layout>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_3">
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="buttonApply">
<property name="enabled">
<bool>false</bool>
</property>
<property name="text">
<string>Accept</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>PasswordComboBox</class>
<extends>QComboBox</extends>
<header location="global">gui/PasswordComboBox.h</header>
</customwidget>
</customwidgets>
<tabstops>
<tabstop>sliderLength</tabstop>
<tabstop>spinBoxLength</tabstop>
<tabstop>checkBoxUpper</tabstop>
<tabstop>checkBoxLower</tabstop>
<tabstop>checkBoxNumbers</tabstop>
<tabstop>checkBoxSpecialChars</tabstop>
<tabstop>checkBoxExcludeAlike</tabstop>
<tabstop>checkBoxEnsureEvery</tabstop>
<tabstop>buttonApply</tabstop>
</tabstops>
<resources/>
<connections/>
<buttongroups>
<buttongroup name="optionButtons">
<property name="exclusive">
<bool>false</bool>
</property>
</buttongroup>
</buttongroups>
</ui>

View File

@ -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();
}

View File

@ -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

View File

@ -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());

View File

@ -114,88 +114,7 @@ Only entries with the same scheme (http://, https://, ftp://, ...) are returned<
</attribute>
<layout class="QVBoxLayout" name="verticalLayout_4">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<layout class="QGridLayout" name="gridLayout_2">
<item row="0" column="0">
<widget class="QCheckBox" name="checkBoxLower">
<property name="text">
<string>Lower letters</string>
</property>
</widget>
</item>
<item row="0" column="1">
<widget class="QCheckBox" name="checkBoxNumbers">
<property name="text">
<string>Numbers</string>
</property>
</widget>
</item>
<item row="1" column="0">
<widget class="QCheckBox" name="checkBoxUpper">
<property name="text">
<string>Upper letters</string>
</property>
</widget>
</item>
<item row="1" column="1">
<widget class="QCheckBox" name="checkBoxSpecialChars">
<property name="text">
<string>Special characters</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="checkBoxEnsureEvery">
<property name="text">
<string>Ensure that the password contains characters from every group</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="checkBoxExcludeAlike">
<property name="text">
<string>Exclude look-alike characters</string>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<widget class="QLabel" name="labelLength">
<property name="text">
<string>Length:</string>
</property>
</widget>
</item>
<item>
<widget class="QSpinBox" name="spinBoxLength">
<property name="minimum">
<number>1</number>
</property>
<property name="maximum">
<number>999</number>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
<widget class="HttpPasswordGeneratorWidget" name="passwordGenerator" native="true"/>
</item>
<item>
<spacer name="verticalSpacer_3">
@ -300,6 +219,19 @@ Only entries with the same scheme (http://, https://, ftp://, ...) are returned<
</item>
</layout>
</widget>
<customwidgets>
<customwidget>
<class>HttpPasswordGeneratorWidget</class>
<extends>QWidget</extends>
<header>http/HttpPasswordGeneratorWidget.h</header>
<container>1</container>
</customwidget>
<customwidget>
<class>PasswordEdit</class>
<extends>QLineEdit</extends>
<header>gui/PasswordEdit.h</header>
</customwidget>
</customwidgets>
<resources/>
<connections/>
</ui>

View File

@ -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()