diff --git a/src/core/PassphraseGenerator.cpp b/src/core/PassphraseGenerator.cpp index 1513338fe..716250f05 100644 --- a/src/core/PassphraseGenerator.cpp +++ b/src/core/PassphraseGenerator.cpp @@ -25,7 +25,7 @@ #include "core/FilePath.h" PassphraseGenerator::PassphraseGenerator() - : m_length(0) + : m_wordCount(0) , m_separator(' ') { const QString path = filePath()->dataPath("wordlists/eff_large.wordlist"); @@ -40,12 +40,12 @@ double PassphraseGenerator::calculateEntropy(QString passphrase) return 0; } - return log(m_wordlist.size()) / log(2.0) * m_length; + return log(m_wordlist.size()) / log(2.0) * m_wordCount; } -void PassphraseGenerator::setLength(int length) +void PassphraseGenerator::setWordCount(int wordCount) { - m_length = length; + m_wordCount = wordCount; } void PassphraseGenerator::setWordlist(QString path) @@ -79,26 +79,21 @@ QString PassphraseGenerator::generatePassphrase() const // In case there was an error loading the wordlist if(m_wordlist.length() == 0) { - QString empty; - return empty; + return QString(); } - QString passphrase; - for (int i = 0; i < m_length; i ++) { - int word_index = randomGen()->randomUInt(m_wordlist.length()); - passphrase.append(m_wordlist.at(word_index)); - - if(i < m_length - 1) { - passphrase.append(m_separator); - } + QStringList words; + for (int i = 0; i < m_wordCount; i++) { + int wordIndex = randomGen()->randomUInt(m_wordlist.length()); + words.append(m_wordlist.at(wordIndex)); } - return passphrase; + return words.join(m_separator); } bool PassphraseGenerator::isValid() const { - if (m_length == 0) { + if (m_wordCount == 0) { return false; } diff --git a/src/core/PassphraseGenerator.h b/src/core/PassphraseGenerator.h index 88e8654ee..729432922 100644 --- a/src/core/PassphraseGenerator.h +++ b/src/core/PassphraseGenerator.h @@ -28,7 +28,7 @@ public: PassphraseGenerator(); double calculateEntropy(QString passphrase); - void setLength(int length); + void setWordCount(int wordCount); void setWordlist(QString path); void setWordseparator(QChar separator); bool isValid() const; @@ -36,7 +36,7 @@ public: QString generatePassphrase() const; private: - int m_length; + int m_wordCount; QChar m_separator; QVector m_wordlist; diff --git a/src/gui/PasswordGeneratorWidget.cpp b/src/gui/PasswordGeneratorWidget.cpp index dac7d0e0a..59f444ebd 100644 --- a/src/gui/PasswordGeneratorWidget.cpp +++ b/src/gui/PasswordGeneratorWidget.cpp @@ -63,7 +63,7 @@ PasswordGeneratorWidget::PasswordGeneratorWidget(QWidget* parent) m_ui->strengthLabel->setFont(defaultFont); } - m_ui->comboBoxWordSeparator->addItems(QStringList() <<" " <<"#" <<";" <<"-" <<":" <<"." <<"@"); + m_ui->comboBoxWordSeparator->addItems(QStringList() << " " << "#" << ";" << "-" << ":" << "." << "@"); QDir path(filePath()->dataPath("wordlists/")); QStringList files = path.entryList(QDir::Files); @@ -84,10 +84,8 @@ void PasswordGeneratorWidget::loadSettings() 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()); - 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()); // Diceware config @@ -106,10 +104,8 @@ void PasswordGeneratorWidget::saveSettings() config()->set("generator/UpperCase", m_ui->checkBoxUpper->isChecked()); config()->set("generator/Numbers", m_ui->checkBoxNumbers->isChecked()); config()->set("generator/SpecialChars", m_ui->checkBoxSpecialChars->isChecked()); - config()->set("generator/ExcludeAlike", m_ui->checkBoxExcludeAlike->isChecked()); config()->set("generator/EnsureEvery", m_ui->checkBoxEnsureEvery->isChecked()); - config()->set("generator/Length", m_ui->spinBoxLength->value()); // Diceware config @@ -356,7 +352,7 @@ void PasswordGeneratorWidget::updateGenerator() m_ui->spinBoxWordCount->setMinimum(minWordCount); m_ui->sliderWordCount->setMinimum(minWordCount); - m_dicewareGenerator->setLength(m_ui->spinBoxWordCount->value()); + m_dicewareGenerator->setWordCount(m_ui->spinBoxWordCount->value()); if (!m_ui->comboBoxWordList->currentText().isEmpty()) { QString path = filePath()->dataPath("wordlists/" + m_ui->comboBoxWordList->currentText()); m_dicewareGenerator->setWordlist(path);