mirror of
https://github.com/keepassxreboot/keepassxc.git
synced 2025-02-17 21:04:19 -05:00
fix wordCount instead of length
This commit is contained in:
parent
be9bd16b4c
commit
98e2c311c3
@ -25,7 +25,7 @@
|
|||||||
#include "core/FilePath.h"
|
#include "core/FilePath.h"
|
||||||
|
|
||||||
PassphraseGenerator::PassphraseGenerator()
|
PassphraseGenerator::PassphraseGenerator()
|
||||||
: m_length(0)
|
: m_wordCount(0)
|
||||||
, m_separator(' ')
|
, m_separator(' ')
|
||||||
{
|
{
|
||||||
const QString path = filePath()->dataPath("wordlists/eff_large.wordlist");
|
const QString path = filePath()->dataPath("wordlists/eff_large.wordlist");
|
||||||
@ -40,12 +40,12 @@ double PassphraseGenerator::calculateEntropy(QString passphrase)
|
|||||||
return 0;
|
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)
|
void PassphraseGenerator::setWordlist(QString path)
|
||||||
@ -79,26 +79,21 @@ QString PassphraseGenerator::generatePassphrase() const
|
|||||||
|
|
||||||
// In case there was an error loading the wordlist
|
// In case there was an error loading the wordlist
|
||||||
if(m_wordlist.length() == 0) {
|
if(m_wordlist.length() == 0) {
|
||||||
QString empty;
|
return QString();
|
||||||
return empty;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
QString passphrase;
|
QStringList words;
|
||||||
for (int i = 0; i < m_length; i ++) {
|
for (int i = 0; i < m_wordCount; i++) {
|
||||||
int word_index = randomGen()->randomUInt(m_wordlist.length());
|
int wordIndex = randomGen()->randomUInt(m_wordlist.length());
|
||||||
passphrase.append(m_wordlist.at(word_index));
|
words.append(m_wordlist.at(wordIndex));
|
||||||
|
|
||||||
if(i < m_length - 1) {
|
|
||||||
passphrase.append(m_separator);
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return passphrase;
|
return words.join(m_separator);
|
||||||
}
|
}
|
||||||
|
|
||||||
bool PassphraseGenerator::isValid() const
|
bool PassphraseGenerator::isValid() const
|
||||||
{
|
{
|
||||||
if (m_length == 0) {
|
if (m_wordCount == 0) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -28,7 +28,7 @@ public:
|
|||||||
PassphraseGenerator();
|
PassphraseGenerator();
|
||||||
|
|
||||||
double calculateEntropy(QString passphrase);
|
double calculateEntropy(QString passphrase);
|
||||||
void setLength(int length);
|
void setWordCount(int wordCount);
|
||||||
void setWordlist(QString path);
|
void setWordlist(QString path);
|
||||||
void setWordseparator(QChar separator);
|
void setWordseparator(QChar separator);
|
||||||
bool isValid() const;
|
bool isValid() const;
|
||||||
@ -36,7 +36,7 @@ public:
|
|||||||
QString generatePassphrase() const;
|
QString generatePassphrase() const;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
int m_length;
|
int m_wordCount;
|
||||||
QChar m_separator;
|
QChar m_separator;
|
||||||
QVector<QString> m_wordlist;
|
QVector<QString> m_wordlist;
|
||||||
|
|
||||||
|
@ -63,7 +63,7 @@ PasswordGeneratorWidget::PasswordGeneratorWidget(QWidget* parent)
|
|||||||
m_ui->strengthLabel->setFont(defaultFont);
|
m_ui->strengthLabel->setFont(defaultFont);
|
||||||
}
|
}
|
||||||
|
|
||||||
m_ui->comboBoxWordSeparator->addItems(QStringList() <<" " <<"#" <<";" <<"-" <<":" <<"." <<"@");
|
m_ui->comboBoxWordSeparator->addItems(QStringList() << " " << "#" << ";" << "-" << ":" << "." << "@");
|
||||||
|
|
||||||
QDir path(filePath()->dataPath("wordlists/"));
|
QDir path(filePath()->dataPath("wordlists/"));
|
||||||
QStringList files = path.entryList(QDir::Files);
|
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->checkBoxUpper->setChecked(config()->get("generator/UpperCase", true).toBool());
|
||||||
m_ui->checkBoxNumbers->setChecked(config()->get("generator/Numbers", true).toBool());
|
m_ui->checkBoxNumbers->setChecked(config()->get("generator/Numbers", true).toBool());
|
||||||
m_ui->checkBoxSpecialChars->setChecked(config()->get("generator/SpecialChars", false).toBool());
|
m_ui->checkBoxSpecialChars->setChecked(config()->get("generator/SpecialChars", false).toBool());
|
||||||
|
|
||||||
m_ui->checkBoxExcludeAlike->setChecked(config()->get("generator/ExcludeAlike", true).toBool());
|
m_ui->checkBoxExcludeAlike->setChecked(config()->get("generator/ExcludeAlike", true).toBool());
|
||||||
m_ui->checkBoxEnsureEvery->setChecked(config()->get("generator/EnsureEvery", true).toBool());
|
m_ui->checkBoxEnsureEvery->setChecked(config()->get("generator/EnsureEvery", true).toBool());
|
||||||
|
|
||||||
m_ui->spinBoxLength->setValue(config()->get("generator/Length", 16).toInt());
|
m_ui->spinBoxLength->setValue(config()->get("generator/Length", 16).toInt());
|
||||||
|
|
||||||
// Diceware config
|
// Diceware config
|
||||||
@ -106,10 +104,8 @@ void PasswordGeneratorWidget::saveSettings()
|
|||||||
config()->set("generator/UpperCase", m_ui->checkBoxUpper->isChecked());
|
config()->set("generator/UpperCase", m_ui->checkBoxUpper->isChecked());
|
||||||
config()->set("generator/Numbers", m_ui->checkBoxNumbers->isChecked());
|
config()->set("generator/Numbers", m_ui->checkBoxNumbers->isChecked());
|
||||||
config()->set("generator/SpecialChars", m_ui->checkBoxSpecialChars->isChecked());
|
config()->set("generator/SpecialChars", m_ui->checkBoxSpecialChars->isChecked());
|
||||||
|
|
||||||
config()->set("generator/ExcludeAlike", m_ui->checkBoxExcludeAlike->isChecked());
|
config()->set("generator/ExcludeAlike", m_ui->checkBoxExcludeAlike->isChecked());
|
||||||
config()->set("generator/EnsureEvery", m_ui->checkBoxEnsureEvery->isChecked());
|
config()->set("generator/EnsureEvery", m_ui->checkBoxEnsureEvery->isChecked());
|
||||||
|
|
||||||
config()->set("generator/Length", m_ui->spinBoxLength->value());
|
config()->set("generator/Length", m_ui->spinBoxLength->value());
|
||||||
|
|
||||||
// Diceware config
|
// Diceware config
|
||||||
@ -356,7 +352,7 @@ void PasswordGeneratorWidget::updateGenerator()
|
|||||||
m_ui->spinBoxWordCount->setMinimum(minWordCount);
|
m_ui->spinBoxWordCount->setMinimum(minWordCount);
|
||||||
m_ui->sliderWordCount->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()) {
|
if (!m_ui->comboBoxWordList->currentText().isEmpty()) {
|
||||||
QString path = filePath()->dataPath("wordlists/" + m_ui->comboBoxWordList->currentText());
|
QString path = filePath()->dataPath("wordlists/" + m_ui->comboBoxWordList->currentText());
|
||||||
m_dicewareGenerator->setWordlist(path);
|
m_dicewareGenerator->setWordlist(path);
|
||||||
|
Loading…
x
Reference in New Issue
Block a user