mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-02-17 13:02:49 -05:00
parent
2ed3201b14
commit
5dadedbf70
@ -23,9 +23,99 @@ PasswordGeneratorWidget::PasswordGeneratorWidget(QWidget* parent)
|
|||||||
, m_ui(new Ui::PasswordGeneratorWidget())
|
, m_ui(new Ui::PasswordGeneratorWidget())
|
||||||
{
|
{
|
||||||
m_ui->setupUi(this);
|
m_ui->setupUi(this);
|
||||||
|
|
||||||
|
connect(m_ui->editNewPassword, SIGNAL(textChanged(QString)), SLOT(updateApplyEnabled(QString)));
|
||||||
|
connect(m_ui->togglePasswordButton, SIGNAL(toggled(bool)), SLOT(togglePassword(bool)));
|
||||||
|
connect(m_ui->buttonGenerate, SIGNAL(clicked()), SLOT(generatePassword()));
|
||||||
|
connect(m_ui->buttonApply, SIGNAL(clicked()), SLOT(emitNewPassword()));
|
||||||
|
|
||||||
|
reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
PasswordGeneratorWidget::~PasswordGeneratorWidget()
|
PasswordGeneratorWidget::~PasswordGeneratorWidget()
|
||||||
{
|
{
|
||||||
;
|
}
|
||||||
|
|
||||||
|
void PasswordGeneratorWidget::reset()
|
||||||
|
{
|
||||||
|
m_ui->checkBoxLower->setChecked(true);
|
||||||
|
m_ui->checkBoxUpper->setChecked(true);
|
||||||
|
m_ui->checkBoxNumbers->setChecked(true);
|
||||||
|
m_ui->checkBoxSpecialChars->setChecked(false);
|
||||||
|
|
||||||
|
m_ui->checkBoxExcludeAlike->setChecked(true);
|
||||||
|
m_ui->checkBoxEnsureEvery->setChecked(true);
|
||||||
|
|
||||||
|
m_ui->spinBoxLength->setValue(16);
|
||||||
|
|
||||||
|
m_ui->editNewPassword->setText("");
|
||||||
|
m_ui->togglePasswordButton->setChecked(true);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PasswordGeneratorWidget::updateApplyEnabled(const QString& password)
|
||||||
|
{
|
||||||
|
m_ui->buttonApply->setEnabled(!password.isEmpty());
|
||||||
|
}
|
||||||
|
|
||||||
|
void PasswordGeneratorWidget::togglePassword(bool checked)
|
||||||
|
{
|
||||||
|
m_ui->editNewPassword->setEchoMode(checked ? QLineEdit::Password : QLineEdit::Normal);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PasswordGeneratorWidget::generatePassword()
|
||||||
|
{
|
||||||
|
int length = m_ui->spinBoxLength->value();
|
||||||
|
PasswordGenerator::CharClasses classes = charClasses();
|
||||||
|
PasswordGenerator::GeneratorFlags flags = generatorFlags();
|
||||||
|
|
||||||
|
if (!passwordGenerator()->isValidCombination(length, classes, flags)) {
|
||||||
|
// TODO: display error
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
QString password = passwordGenerator()->generatePassword(length, classes, flags);
|
||||||
|
m_ui->editNewPassword->setText(password);
|
||||||
|
}
|
||||||
|
|
||||||
|
void PasswordGeneratorWidget::emitNewPassword()
|
||||||
|
{
|
||||||
|
Q_EMIT newPassword(m_ui->editNewPassword->text());
|
||||||
|
}
|
||||||
|
|
||||||
|
PasswordGenerator::CharClasses PasswordGeneratorWidget::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 PasswordGeneratorWidget::generatorFlags()
|
||||||
|
{
|
||||||
|
PasswordGenerator::GeneratorFlags flags;
|
||||||
|
|
||||||
|
if (m_ui->checkBoxExcludeAlike->isChecked()) {
|
||||||
|
flags |= PasswordGenerator::ExcludeLookAlike;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (m_ui->checkBoxEnsureEvery->isChecked()) {
|
||||||
|
flags |= PasswordGenerator::CharFromEveryGroup;
|
||||||
|
}
|
||||||
|
|
||||||
|
return flags;
|
||||||
}
|
}
|
||||||
|
@ -21,6 +21,7 @@
|
|||||||
#include <QtGui/QWidget>
|
#include <QtGui/QWidget>
|
||||||
|
|
||||||
#include "core/Global.h"
|
#include "core/Global.h"
|
||||||
|
#include "core/PasswordGenerator.h"
|
||||||
|
|
||||||
namespace Ui {
|
namespace Ui {
|
||||||
class PasswordGeneratorWidget;
|
class PasswordGeneratorWidget;
|
||||||
@ -33,8 +34,21 @@ class PasswordGeneratorWidget : public QWidget
|
|||||||
public:
|
public:
|
||||||
explicit PasswordGeneratorWidget(QWidget* parent = Q_NULLPTR);
|
explicit PasswordGeneratorWidget(QWidget* parent = Q_NULLPTR);
|
||||||
~PasswordGeneratorWidget();
|
~PasswordGeneratorWidget();
|
||||||
|
void reset();
|
||||||
|
|
||||||
|
Q_SIGNALS:
|
||||||
|
void newPassword(const QString& password);
|
||||||
|
|
||||||
|
private Q_SLOTS:
|
||||||
|
void updateApplyEnabled(const QString& password);
|
||||||
|
void togglePassword(bool checked);
|
||||||
|
void generatePassword();
|
||||||
|
void emitNewPassword();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
PasswordGenerator::CharClasses charClasses();
|
||||||
|
PasswordGenerator::GeneratorFlags generatorFlags();
|
||||||
|
|
||||||
const QScopedPointer<Ui::PasswordGeneratorWidget> m_ui;
|
const QScopedPointer<Ui::PasswordGeneratorWidget> m_ui;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
@ -6,21 +6,169 @@
|
|||||||
<rect>
|
<rect>
|
||||||
<x>0</x>
|
<x>0</x>
|
||||||
<y>0</y>
|
<y>0</y>
|
||||||
<width>383</width>
|
<width>468</width>
|
||||||
<height>181</height>
|
<height>298</height>
|
||||||
</rect>
|
</rect>
|
||||||
</property>
|
</property>
|
||||||
<property name="windowTitle">
|
<property name="windowTitle">
|
||||||
<string/>
|
<string/>
|
||||||
</property>
|
</property>
|
||||||
<layout class="QHBoxLayout" name="horizontalLayout">
|
<layout class="QVBoxLayout" name="verticalLayout">
|
||||||
<item>
|
<item>
|
||||||
<widget class="QLabel" name="label">
|
<widget class="QLabel" name="labelGroups">
|
||||||
<property name="text">
|
<property name="text">
|
||||||
<string>Password Generator</string>
|
<string>Use the following password groups:</string>
|
||||||
</property>
|
</property>
|
||||||
</widget>
|
</widget>
|
||||||
</item>
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout">
|
||||||
|
<item>
|
||||||
|
<spacer name="horizontalSpacer">
|
||||||
|
<property name="orientation">
|
||||||
|
<enum>Qt::Horizontal</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeType">
|
||||||
|
<enum>QSizePolicy::Maximum</enum>
|
||||||
|
</property>
|
||||||
|
<property name="sizeHint" stdset="0">
|
||||||
|
<size>
|
||||||
|
<width>20</width>
|
||||||
|
<height>1</height>
|
||||||
|
</size>
|
||||||
|
</property>
|
||||||
|
</spacer>
|
||||||
|
</item>
|
||||||
|
<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="checkBoxExcludeAlike">
|
||||||
|
<property name="text">
|
||||||
|
<string>Exclude look-alike characters</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</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>
|
||||||
|
<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>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<layout class="QHBoxLayout" name="horizontalLayout_3">
|
||||||
|
<item>
|
||||||
|
<widget class="QLabel" name="labelNewPassword">
|
||||||
|
<property name="text">
|
||||||
|
<string>New password:</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QLineEdit" name="editNewPassword">
|
||||||
|
<property name="echoMode">
|
||||||
|
<enum>QLineEdit::Password</enum>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QToolButton" name="togglePasswordButton">
|
||||||
|
<property name="text">
|
||||||
|
<string>...</string>
|
||||||
|
</property>
|
||||||
|
<property name="checkable">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
<property name="checked">
|
||||||
|
<bool>true</bool>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="buttonGenerate">
|
||||||
|
<property name="text">
|
||||||
|
<string>Generate</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
<item>
|
||||||
|
<widget class="QPushButton" name="buttonApply">
|
||||||
|
<property name="enabled">
|
||||||
|
<bool>false</bool>
|
||||||
|
</property>
|
||||||
|
<property name="text">
|
||||||
|
<string>Apply</string>
|
||||||
|
</property>
|
||||||
|
</widget>
|
||||||
|
</item>
|
||||||
|
</layout>
|
||||||
|
</item>
|
||||||
</layout>
|
</layout>
|
||||||
</widget>
|
</widget>
|
||||||
<resources/>
|
<resources/>
|
||||||
|
@ -92,11 +92,13 @@ void EditEntryWidget::setupMain()
|
|||||||
connect(m_mainUi->expireCheck, SIGNAL(toggled(bool)), m_mainUi->expireDatePicker, SLOT(setEnabled(bool)));
|
connect(m_mainUi->expireCheck, SIGNAL(toggled(bool)), m_mainUi->expireDatePicker, SLOT(setEnabled(bool)));
|
||||||
connect(m_mainUi->passwordEdit, SIGNAL(textEdited(QString)), SLOT(setPasswordCheckColors()));
|
connect(m_mainUi->passwordEdit, SIGNAL(textEdited(QString)), SLOT(setPasswordCheckColors()));
|
||||||
connect(m_mainUi->passwordRepeatEdit, SIGNAL(textEdited(QString)), SLOT(setPasswordCheckColors()));
|
connect(m_mainUi->passwordRepeatEdit, SIGNAL(textEdited(QString)), SLOT(setPasswordCheckColors()));
|
||||||
|
connect(m_mainUi->passwordGenerator, SIGNAL(newPassword(QString)), SLOT(setGeneratedPassword(QString)));
|
||||||
|
|
||||||
m_mainUi->expirePresets->setMenu(createPresetsMenu());
|
m_mainUi->expirePresets->setMenu(createPresetsMenu());
|
||||||
connect(m_mainUi->expirePresets->menu(), SIGNAL(triggered(QAction*)), this, SLOT(useExpiryPreset(QAction*)));
|
connect(m_mainUi->expirePresets->menu(), SIGNAL(triggered(QAction*)), this, SLOT(useExpiryPreset(QAction*)));
|
||||||
|
|
||||||
m_mainUi->passwordGenerator->hide();
|
m_mainUi->passwordGenerator->hide();
|
||||||
|
m_mainUi->passwordGenerator->reset();
|
||||||
}
|
}
|
||||||
|
|
||||||
void EditEntryWidget::setupAdvanced()
|
void EditEntryWidget::setupAdvanced()
|
||||||
@ -279,6 +281,7 @@ void EditEntryWidget::setForms(const Entry* entry, bool restore)
|
|||||||
m_mainUi->expireDatePicker->setReadOnly(m_history);
|
m_mainUi->expireDatePicker->setReadOnly(m_history);
|
||||||
m_mainUi->notesEdit->setReadOnly(m_history);
|
m_mainUi->notesEdit->setReadOnly(m_history);
|
||||||
m_mainUi->tooglePasswordGeneratorButton->setChecked(false);
|
m_mainUi->tooglePasswordGeneratorButton->setChecked(false);
|
||||||
|
m_mainUi->passwordGenerator->reset();
|
||||||
m_advancedUi->addAttachmentButton->setEnabled(!m_history);
|
m_advancedUi->addAttachmentButton->setEnabled(!m_history);
|
||||||
m_advancedUi->removeAttachmentButton->setEnabled(!m_history);
|
m_advancedUi->removeAttachmentButton->setEnabled(!m_history);
|
||||||
m_advancedUi->addAttributeButton->setEnabled(!m_history);
|
m_advancedUi->addAttributeButton->setEnabled(!m_history);
|
||||||
@ -510,6 +513,14 @@ void EditEntryWidget::setPasswordCheckColors()
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void EditEntryWidget::setGeneratedPassword(const QString& password)
|
||||||
|
{
|
||||||
|
m_mainUi->passwordEdit->setText(password);
|
||||||
|
m_mainUi->passwordRepeatEdit->setText(password);
|
||||||
|
|
||||||
|
m_mainUi->tooglePasswordGeneratorButton->setChecked(false);
|
||||||
|
}
|
||||||
|
|
||||||
void EditEntryWidget::insertAttribute()
|
void EditEntryWidget::insertAttribute()
|
||||||
{
|
{
|
||||||
Q_ASSERT(!m_history);
|
Q_ASSERT(!m_history);
|
||||||
|
@ -74,6 +74,7 @@ private Q_SLOTS:
|
|||||||
void togglePassword(bool checked);
|
void togglePassword(bool checked);
|
||||||
void togglePasswordGeneratorButton(bool checked);
|
void togglePasswordGeneratorButton(bool checked);
|
||||||
void setPasswordCheckColors();
|
void setPasswordCheckColors();
|
||||||
|
void setGeneratedPassword(const QString& password);
|
||||||
void insertAttribute();
|
void insertAttribute();
|
||||||
void editCurrentAttribute();
|
void editCurrentAttribute();
|
||||||
void removeCurrentAttribute();
|
void removeCurrentAttribute();
|
||||||
|
Loading…
x
Reference in New Issue
Block a user