2013-03-10 17:23:10 -04:00
|
|
|
/*
|
|
|
|
* 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 "PasswordGeneratorWidget.h"
|
|
|
|
#include "ui_PasswordGeneratorWidget.h"
|
|
|
|
|
2014-01-12 17:33:36 -05:00
|
|
|
#include <QLineEdit>
|
2017-03-04 09:10:50 -05:00
|
|
|
#include <QDir>
|
2014-01-12 17:33:36 -05:00
|
|
|
|
2013-06-28 22:29:03 -04:00
|
|
|
#include "core/Config.h"
|
2014-01-12 17:33:36 -05:00
|
|
|
#include "core/PasswordGenerator.h"
|
|
|
|
#include "core/FilePath.h"
|
2017-05-28 13:47:33 -04:00
|
|
|
#include "gui/Clipboard.h"
|
2013-06-28 22:29:03 -04:00
|
|
|
|
2013-03-10 17:23:10 -04:00
|
|
|
PasswordGeneratorWidget::PasswordGeneratorWidget(QWidget* parent)
|
|
|
|
: QWidget(parent)
|
2014-01-12 17:33:36 -05:00
|
|
|
, m_updatingSpinBox(false)
|
2017-03-04 09:10:50 -05:00
|
|
|
, m_passwordGenerator(new PasswordGenerator())
|
|
|
|
, m_dicewareGenerator(new PassphraseGenerator())
|
2013-03-10 17:23:10 -04:00
|
|
|
, m_ui(new Ui::PasswordGeneratorWidget())
|
|
|
|
{
|
|
|
|
m_ui->setupUi(this);
|
2013-03-12 17:42:06 -04:00
|
|
|
|
2014-01-12 17:33:36 -05:00
|
|
|
m_ui->togglePasswordButton->setIcon(filePath()->onOffIcon("actions", "password-show"));
|
|
|
|
|
2016-11-23 21:59:24 -05:00
|
|
|
connect(m_ui->editNewPassword, SIGNAL(textChanged(QString)), SLOT(updateApplyEnabled(QString)));
|
|
|
|
connect(m_ui->editNewPassword, SIGNAL(textChanged(QString)), SLOT(updatePasswordStrength(QString)));
|
|
|
|
connect(m_ui->togglePasswordButton, SIGNAL(toggled(bool)), SLOT(togglePasswordShown(bool)));
|
|
|
|
connect(m_ui->buttonApply, SIGNAL(clicked()), SLOT(applyPassword()));
|
2017-05-28 13:47:33 -04:00
|
|
|
connect(m_ui->buttonCopy, SIGNAL(clicked()), SLOT(copyPassword()));
|
2017-03-04 09:10:50 -05:00
|
|
|
connect(m_ui->buttonGenerate, SIGNAL(clicked()), SLOT(regeneratePassword()));
|
2013-03-12 17:42:06 -04:00
|
|
|
|
2017-03-04 09:10:50 -05:00
|
|
|
connect(m_ui->sliderLength, SIGNAL(valueChanged(int)), SLOT(passwordSliderMoved()));
|
|
|
|
connect(m_ui->spinBoxLength, SIGNAL(valueChanged(int)), SLOT(passwordSpinBoxChanged()));
|
2014-01-12 17:33:36 -05:00
|
|
|
|
2017-03-04 09:10:50 -05:00
|
|
|
connect(m_ui->sliderWordCount, SIGNAL(valueChanged(int)), SLOT(dicewareSliderMoved()));
|
|
|
|
connect(m_ui->spinBoxWordCount, SIGNAL(valueChanged(int)), SLOT(dicewareSpinBoxChanged()));
|
|
|
|
|
2017-03-16 20:43:50 -04:00
|
|
|
connect(m_ui->editWordSeparator, SIGNAL(textChanged(QString)), SLOT(updateGenerator()));
|
2017-03-04 09:10:50 -05:00
|
|
|
connect(m_ui->comboBoxWordList, SIGNAL(currentIndexChanged(int)), SLOT(updateGenerator()));
|
2014-01-12 17:33:36 -05:00
|
|
|
connect(m_ui->optionButtons, SIGNAL(buttonClicked(int)), SLOT(updateGenerator()));
|
2017-03-04 09:10:50 -05:00
|
|
|
connect(m_ui->tabWidget, SIGNAL(currentChanged(int)), SLOT(updateGenerator()));
|
2014-01-12 17:33:36 -05:00
|
|
|
|
2017-01-27 11:44:40 -05:00
|
|
|
// set font size of password quality and entropy labels dynamically to 80% of
|
|
|
|
// the default font size, but make it no smaller than 8pt
|
2016-11-23 21:59:24 -05:00
|
|
|
QFont defaultFont;
|
2017-01-27 11:44:40 -05:00
|
|
|
int smallerSize = static_cast<int>(defaultFont.pointSize() * 0.8f);
|
|
|
|
if (smallerSize >= 8) {
|
|
|
|
defaultFont.setPointSize(smallerSize);
|
|
|
|
m_ui->entropyLabel->setFont(defaultFont);
|
|
|
|
m_ui->strengthLabel->setFont(defaultFont);
|
|
|
|
}
|
2017-03-04 09:10:50 -05:00
|
|
|
|
2017-03-16 20:43:50 -04:00
|
|
|
// set default separator to Space
|
|
|
|
m_ui->editWordSeparator->setText(" ");
|
2017-03-04 09:10:50 -05:00
|
|
|
|
|
|
|
QDir path(filePath()->dataPath("wordlists/"));
|
|
|
|
QStringList files = path.entryList(QDir::Files);
|
|
|
|
m_ui->comboBoxWordList->addItems(files);
|
2017-03-16 19:44:51 -04:00
|
|
|
if (files.size() > 1) {
|
|
|
|
m_ui->comboBoxWordList->setVisible(true);
|
|
|
|
m_ui->labelWordList->setVisible(true);
|
|
|
|
} else {
|
|
|
|
m_ui->comboBoxWordList->setVisible(false);
|
|
|
|
m_ui->labelWordList->setVisible(false);
|
|
|
|
}
|
2016-11-23 21:59:24 -05:00
|
|
|
|
2013-06-28 22:29:03 -04:00
|
|
|
loadSettings();
|
2014-01-12 17:33:36 -05:00
|
|
|
reset();
|
2013-03-10 17:23:10 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
PasswordGeneratorWidget::~PasswordGeneratorWidget()
|
|
|
|
{
|
2013-03-12 17:42:06 -04:00
|
|
|
}
|
|
|
|
|
2013-06-28 22:29:03 -04:00
|
|
|
void PasswordGeneratorWidget::loadSettings()
|
|
|
|
{
|
2017-03-04 09:10:50 -05:00
|
|
|
// Password config
|
2013-06-28 22:29:03 -04:00
|
|
|
m_ui->checkBoxLower->setChecked(config()->get("generator/LowerCase", true).toBool());
|
|
|
|
m_ui->checkBoxUpper->setChecked(config()->get("generator/UpperCase", true).toBool());
|
|
|
|
m_ui->checkBoxNumbers->setChecked(config()->get("generator/Numbers", true).toBool());
|
|
|
|
m_ui->checkBoxSpecialChars->setChecked(config()->get("generator/SpecialChars", false).toBool());
|
2017-04-28 15:36:43 -04:00
|
|
|
m_ui->checkBoxExtASCII->setChecked(config()->get("generator/EASCII", false).toBool());
|
2013-06-28 22:29:03 -04:00
|
|
|
m_ui->checkBoxExcludeAlike->setChecked(config()->get("generator/ExcludeAlike", true).toBool());
|
|
|
|
m_ui->checkBoxEnsureEvery->setChecked(config()->get("generator/EnsureEvery", true).toBool());
|
|
|
|
m_ui->spinBoxLength->setValue(config()->get("generator/Length", 16).toInt());
|
2017-03-04 09:10:50 -05:00
|
|
|
|
|
|
|
// Diceware config
|
|
|
|
m_ui->spinBoxWordCount->setValue(config()->get("generator/WordCount", 6).toInt());
|
2017-03-16 20:43:50 -04:00
|
|
|
m_ui->editWordSeparator->setText(config()->get("generator/WordSeparator", " ").toString());
|
2017-03-04 09:10:50 -05:00
|
|
|
m_ui->comboBoxWordList->setCurrentText(config()->get("generator/WordList", "eff_large.wordlist").toString());
|
|
|
|
|
|
|
|
// Password or diceware?
|
2017-03-04 13:24:08 -05:00
|
|
|
m_ui->tabWidget->setCurrentIndex(config()->get("generator/Type", 0).toInt());
|
2013-06-28 22:29:03 -04:00
|
|
|
}
|
|
|
|
|
|
|
|
void PasswordGeneratorWidget::saveSettings()
|
2013-03-12 17:42:06 -04:00
|
|
|
{
|
2017-03-04 09:10:50 -05:00
|
|
|
// Password config
|
2013-06-28 22:29:03 -04:00
|
|
|
config()->set("generator/LowerCase", m_ui->checkBoxLower->isChecked());
|
|
|
|
config()->set("generator/UpperCase", m_ui->checkBoxUpper->isChecked());
|
|
|
|
config()->set("generator/Numbers", m_ui->checkBoxNumbers->isChecked());
|
|
|
|
config()->set("generator/SpecialChars", m_ui->checkBoxSpecialChars->isChecked());
|
2017-04-28 15:36:43 -04:00
|
|
|
config()->set("generator/EASCII", m_ui->checkBoxExtASCII->isChecked());
|
2013-06-28 22:29:03 -04:00
|
|
|
config()->set("generator/ExcludeAlike", m_ui->checkBoxExcludeAlike->isChecked());
|
|
|
|
config()->set("generator/EnsureEvery", m_ui->checkBoxEnsureEvery->isChecked());
|
|
|
|
config()->set("generator/Length", m_ui->spinBoxLength->value());
|
2017-03-04 09:10:50 -05:00
|
|
|
|
|
|
|
// Diceware config
|
|
|
|
config()->set("generator/WordCount", m_ui->spinBoxWordCount->value());
|
2017-03-16 20:43:50 -04:00
|
|
|
config()->set("generator/WordSeparator", m_ui->editWordSeparator->text());
|
2017-03-04 09:10:50 -05:00
|
|
|
config()->set("generator/WordList", m_ui->comboBoxWordList->currentText());
|
|
|
|
|
|
|
|
// Password or diceware?
|
|
|
|
config()->set("generator/Type", m_ui->tabWidget->currentIndex());
|
2013-06-28 22:29:03 -04:00
|
|
|
}
|
2013-03-12 17:42:06 -04:00
|
|
|
|
2013-06-28 22:29:03 -04:00
|
|
|
void PasswordGeneratorWidget::reset()
|
|
|
|
{
|
2016-11-23 21:59:24 -05:00
|
|
|
m_ui->editNewPassword->setText("");
|
|
|
|
setStandaloneMode(false);
|
|
|
|
togglePasswordShown(config()->get("security/passwordscleartext").toBool());
|
2014-01-12 17:33:36 -05:00
|
|
|
updateGenerator();
|
2013-03-12 17:42:06 -04:00
|
|
|
}
|
|
|
|
|
2016-11-23 21:59:24 -05:00
|
|
|
void PasswordGeneratorWidget::setStandaloneMode(bool standalone)
|
|
|
|
{
|
|
|
|
if (standalone) {
|
|
|
|
m_ui->buttonApply->setText(tr("Close"));
|
|
|
|
togglePasswordShown(true);
|
|
|
|
} else {
|
|
|
|
m_ui->buttonApply->setText(tr("Apply"));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2016-08-06 05:29:47 -04:00
|
|
|
void PasswordGeneratorWidget::regeneratePassword()
|
2017-03-04 09:10:50 -05:00
|
|
|
{
|
|
|
|
if (m_ui->tabWidget->currentIndex() == Password) {
|
|
|
|
if (m_passwordGenerator->isValid()) {
|
|
|
|
QString password = m_passwordGenerator->generatePassword();
|
|
|
|
m_ui->editNewPassword->setText(password);
|
|
|
|
updatePasswordStrength(password);
|
|
|
|
}
|
|
|
|
} else {
|
|
|
|
if (m_dicewareGenerator->isValid()) {
|
|
|
|
QString password = m_dicewareGenerator->generatePassphrase();
|
|
|
|
m_ui->editNewPassword->setText(password);
|
|
|
|
updatePasswordStrength(password);
|
|
|
|
}
|
2016-08-06 05:29:47 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-12 17:42:06 -04:00
|
|
|
void PasswordGeneratorWidget::updateApplyEnabled(const QString& password)
|
|
|
|
{
|
|
|
|
m_ui->buttonApply->setEnabled(!password.isEmpty());
|
|
|
|
}
|
|
|
|
|
2016-11-23 21:59:24 -05:00
|
|
|
void PasswordGeneratorWidget::updatePasswordStrength(const QString& password)
|
|
|
|
{
|
2017-03-04 09:10:50 -05:00
|
|
|
double entropy = 0.0;
|
|
|
|
if (m_ui->tabWidget->currentIndex() == Password) {
|
|
|
|
entropy = m_passwordGenerator->calculateEntropy(password);
|
|
|
|
} else {
|
|
|
|
entropy = m_dicewareGenerator->calculateEntropy(password);
|
|
|
|
}
|
|
|
|
|
2016-11-23 21:59:24 -05:00
|
|
|
m_ui->entropyLabel->setText(tr("Entropy: %1 bit").arg(QString::number(entropy, 'f', 2)));
|
|
|
|
|
|
|
|
if (entropy > m_ui->entropyProgressBar->maximum()) {
|
|
|
|
entropy = m_ui->entropyProgressBar->maximum();
|
|
|
|
}
|
|
|
|
m_ui->entropyProgressBar->setValue(entropy);
|
|
|
|
|
|
|
|
colorStrengthIndicator(entropy);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PasswordGeneratorWidget::applyPassword()
|
2013-03-12 17:42:06 -04:00
|
|
|
{
|
2016-11-23 21:59:24 -05:00
|
|
|
saveSettings();
|
2017-03-10 09:58:42 -05:00
|
|
|
emit appliedPassword(m_ui->editNewPassword->text());
|
|
|
|
emit dialogTerminated();
|
2014-01-12 17:33:36 -05:00
|
|
|
}
|
2013-03-12 17:42:06 -04:00
|
|
|
|
2017-05-28 13:47:33 -04:00
|
|
|
void PasswordGeneratorWidget::copyPassword()
|
|
|
|
{
|
|
|
|
clipboard()->setText(m_ui->editNewPassword->text());
|
|
|
|
}
|
|
|
|
|
2017-03-04 09:10:50 -05:00
|
|
|
void PasswordGeneratorWidget::passwordSliderMoved()
|
2014-01-12 17:33:36 -05:00
|
|
|
{
|
|
|
|
if (m_updatingSpinBox) {
|
2013-03-12 17:42:06 -04:00
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-12 17:33:36 -05:00
|
|
|
m_ui->spinBoxLength->setValue(m_ui->sliderLength->value());
|
|
|
|
|
|
|
|
updateGenerator();
|
2013-03-12 17:42:06 -04:00
|
|
|
}
|
|
|
|
|
2017-03-04 09:10:50 -05:00
|
|
|
void PasswordGeneratorWidget::passwordSpinBoxChanged()
|
2013-03-12 17:42:06 -04:00
|
|
|
{
|
2016-07-31 16:07:47 -04:00
|
|
|
if (m_updatingSpinBox) {
|
|
|
|
return;
|
|
|
|
}
|
|
|
|
|
2014-01-12 17:33:36 -05:00
|
|
|
// 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();
|
2013-03-12 17:42:06 -04:00
|
|
|
}
|
|
|
|
|
2017-03-04 09:10:50 -05:00
|
|
|
void PasswordGeneratorWidget::dicewareSliderMoved()
|
|
|
|
{
|
|
|
|
m_ui->spinBoxWordCount->setValue(m_ui->sliderWordCount->value());
|
|
|
|
|
|
|
|
updateGenerator();
|
|
|
|
}
|
|
|
|
|
|
|
|
void PasswordGeneratorWidget::dicewareSpinBoxChanged()
|
|
|
|
{
|
|
|
|
m_ui->sliderWordCount->setValue(m_ui->spinBoxWordCount->value());
|
|
|
|
|
|
|
|
updateGenerator();
|
|
|
|
}
|
|
|
|
|
2016-11-23 21:59:24 -05:00
|
|
|
void PasswordGeneratorWidget::togglePasswordShown(bool showing)
|
|
|
|
{
|
|
|
|
m_ui->editNewPassword->setShowPassword(showing);
|
|
|
|
bool blockSignals = m_ui->togglePasswordButton->blockSignals(true);
|
|
|
|
m_ui->togglePasswordButton->setChecked(showing);
|
|
|
|
m_ui->togglePasswordButton->blockSignals(blockSignals);
|
|
|
|
}
|
|
|
|
|
|
|
|
void PasswordGeneratorWidget::colorStrengthIndicator(double entropy)
|
|
|
|
{
|
|
|
|
// Take the existing stylesheet and convert the text and background color to arguments
|
|
|
|
QString style = m_ui->entropyProgressBar->styleSheet();
|
|
|
|
QRegularExpression re("(QProgressBar::chunk\\s*\\{.*?background-color:)[^;]+;",
|
|
|
|
QRegularExpression::CaseInsensitiveOption |
|
|
|
|
QRegularExpression::DotMatchesEverythingOption);
|
|
|
|
style.replace(re, "\\1 %1;");
|
|
|
|
|
|
|
|
// Set the color and background based on entropy
|
|
|
|
// colors are taking from the KDE breeze palette
|
|
|
|
// <https://community.kde.org/KDE_Visual_Design_Group/HIG/Color>
|
2017-03-04 09:10:50 -05:00
|
|
|
if (entropy < 40) {
|
2016-11-23 21:59:24 -05:00
|
|
|
m_ui->entropyProgressBar->setStyleSheet(style.arg("#c0392b"));
|
|
|
|
m_ui->strengthLabel->setText(tr("Password Quality: %1").arg(tr("Poor")));
|
2017-03-04 09:10:50 -05:00
|
|
|
} else if (entropy >= 40 && entropy < 65) {
|
2016-11-23 21:59:24 -05:00
|
|
|
m_ui->entropyProgressBar->setStyleSheet(style.arg("#f39c1f"));
|
|
|
|
m_ui->strengthLabel->setText(tr("Password Quality: %1").arg(tr("Weak")));
|
2017-03-04 09:10:50 -05:00
|
|
|
} else if (entropy >= 65 && entropy < 100) {
|
2016-11-23 21:59:24 -05:00
|
|
|
m_ui->entropyProgressBar->setStyleSheet(style.arg("#11d116"));
|
|
|
|
m_ui->strengthLabel->setText(tr("Password Quality: %1").arg(tr("Good")));
|
|
|
|
} else {
|
|
|
|
m_ui->entropyProgressBar->setStyleSheet(style.arg("#27ae60"));
|
|
|
|
m_ui->strengthLabel->setText(tr("Password Quality: %1").arg(tr("Excellent")));
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2013-03-12 17:42:06 -04:00
|
|
|
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;
|
|
|
|
}
|
|
|
|
|
2017-04-28 15:36:43 -04:00
|
|
|
if (m_ui->checkBoxExtASCII->isChecked()) {
|
|
|
|
classes |= PasswordGenerator::EASCII;
|
|
|
|
}
|
|
|
|
|
2013-03-12 17:42:06 -04:00
|
|
|
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;
|
2013-03-10 17:23:10 -04:00
|
|
|
}
|
2014-01-12 17:33:36 -05:00
|
|
|
|
|
|
|
void PasswordGeneratorWidget::updateGenerator()
|
|
|
|
{
|
2017-03-04 09:10:50 -05:00
|
|
|
if (m_ui->tabWidget->currentIndex() == Password) {
|
|
|
|
PasswordGenerator::CharClasses classes = charClasses();
|
|
|
|
PasswordGenerator::GeneratorFlags flags = generatorFlags();
|
|
|
|
|
|
|
|
int minLength = 0;
|
|
|
|
if (flags.testFlag(PasswordGenerator::CharFromEveryGroup)) {
|
|
|
|
if (classes.testFlag(PasswordGenerator::LowerLetters)) {
|
|
|
|
minLength++;
|
|
|
|
}
|
|
|
|
if (classes.testFlag(PasswordGenerator::UpperLetters)) {
|
|
|
|
minLength++;
|
|
|
|
}
|
|
|
|
if (classes.testFlag(PasswordGenerator::Numbers)) {
|
|
|
|
minLength++;
|
|
|
|
}
|
|
|
|
if (classes.testFlag(PasswordGenerator::SpecialCharacters)) {
|
|
|
|
minLength++;
|
|
|
|
}
|
2017-04-28 15:36:43 -04:00
|
|
|
if (classes.testFlag(PasswordGenerator::EASCII)) {
|
|
|
|
minLength++;
|
|
|
|
}
|
2016-07-31 16:07:47 -04:00
|
|
|
}
|
2017-03-04 09:10:50 -05:00
|
|
|
minLength = qMax(minLength, 1);
|
|
|
|
|
|
|
|
if (m_ui->spinBoxLength->value() < minLength) {
|
|
|
|
m_updatingSpinBox = true;
|
|
|
|
m_ui->spinBoxLength->setValue(minLength);
|
|
|
|
m_ui->sliderLength->setValue(minLength);
|
|
|
|
m_updatingSpinBox = false;
|
2016-07-31 16:07:47 -04:00
|
|
|
}
|
2017-03-04 09:10:50 -05:00
|
|
|
|
|
|
|
m_ui->spinBoxLength->setMinimum(minLength);
|
|
|
|
m_ui->sliderLength->setMinimum(minLength);
|
|
|
|
|
|
|
|
m_passwordGenerator->setLength(m_ui->spinBoxLength->value());
|
|
|
|
m_passwordGenerator->setCharClasses(classes);
|
|
|
|
m_passwordGenerator->setFlags(flags);
|
|
|
|
|
|
|
|
if (m_passwordGenerator->isValid()) {
|
|
|
|
m_ui->buttonGenerate->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
m_ui->buttonGenerate->setEnabled(false);
|
2016-07-31 16:07:47 -04:00
|
|
|
}
|
2017-03-04 09:10:50 -05:00
|
|
|
} else {
|
2017-03-16 19:34:13 -04:00
|
|
|
int minWordCount = 1;
|
2016-07-31 16:07:47 -04:00
|
|
|
|
2017-03-04 09:10:50 -05:00
|
|
|
if (m_ui->spinBoxWordCount->value() < minWordCount) {
|
|
|
|
m_updatingSpinBox = true;
|
|
|
|
m_ui->spinBoxWordCount->setValue(minWordCount);
|
|
|
|
m_ui->sliderWordCount->setValue(minWordCount);
|
|
|
|
m_updatingSpinBox = false;
|
|
|
|
}
|
2016-07-31 16:07:47 -04:00
|
|
|
|
2017-03-04 09:10:50 -05:00
|
|
|
m_ui->spinBoxWordCount->setMinimum(minWordCount);
|
|
|
|
m_ui->sliderWordCount->setMinimum(minWordCount);
|
2016-07-31 16:07:47 -04:00
|
|
|
|
2017-03-04 16:28:41 -05:00
|
|
|
m_dicewareGenerator->setWordCount(m_ui->spinBoxWordCount->value());
|
2017-03-04 09:10:50 -05:00
|
|
|
if (!m_ui->comboBoxWordList->currentText().isEmpty()) {
|
|
|
|
QString path = filePath()->dataPath("wordlists/" + m_ui->comboBoxWordList->currentText());
|
2017-03-21 19:04:36 -04:00
|
|
|
m_dicewareGenerator->setWordList(path);
|
2017-03-04 09:10:50 -05:00
|
|
|
}
|
2017-03-21 19:04:36 -04:00
|
|
|
m_dicewareGenerator->setWordSeparator(m_ui->editWordSeparator->text());
|
2014-01-12 17:33:36 -05:00
|
|
|
|
2017-03-04 09:10:50 -05:00
|
|
|
if (m_dicewareGenerator->isValid()) {
|
|
|
|
m_ui->buttonGenerate->setEnabled(true);
|
|
|
|
} else {
|
|
|
|
m_ui->buttonGenerate->setEnabled(false);
|
|
|
|
}
|
2017-01-26 18:38:50 -05:00
|
|
|
}
|
|
|
|
|
2016-08-06 05:29:47 -04:00
|
|
|
regeneratePassword();
|
2014-01-12 17:33:36 -05:00
|
|
|
}
|