diff --git a/src/browser/BrowserSettings.cpp b/src/browser/BrowserSettings.cpp index 2df7fc1c5..ecaf8e23e 100755 --- a/src/browser/BrowserSettings.cpp +++ b/src/browser/BrowserSettings.cpp @@ -211,7 +211,7 @@ void BrowserSettings::setVivaldiSupport(bool enabled) { bool BrowserSettings::passwordUseNumbers() { - return config()->get("generator/Numbers", true).toBool(); + return config()->get("generator/Numbers", PasswordGenerator::DefaultNumbers).toBool(); } void BrowserSettings::setPasswordUseNumbers(bool useNumbers) @@ -221,7 +221,7 @@ void BrowserSettings::setPasswordUseNumbers(bool useNumbers) bool BrowserSettings::passwordUseLowercase() { - return config()->get("generator/LowerCase", true).toBool(); + return config()->get("generator/LowerCase", PasswordGenerator::DefaultLower).toBool(); } void BrowserSettings::setPasswordUseLowercase(bool useLowercase) @@ -231,7 +231,7 @@ void BrowserSettings::setPasswordUseLowercase(bool useLowercase) bool BrowserSettings::passwordUseUppercase() { - return config()->get("generator/UpperCase", true).toBool(); + return config()->get("generator/UpperCase", PasswordGenerator::DefaultUpper).toBool(); } void BrowserSettings::setPasswordUseUppercase(bool useUppercase) @@ -241,7 +241,7 @@ void BrowserSettings::setPasswordUseUppercase(bool useUppercase) bool BrowserSettings::passwordUseSpecial() { - return config()->get("generator/SpecialChars", false).toBool(); + return config()->get("generator/SpecialChars", PasswordGenerator::DefaultSpecial).toBool(); } void BrowserSettings::setPasswordUseSpecial(bool useSpecial) @@ -251,7 +251,7 @@ void BrowserSettings::setPasswordUseSpecial(bool useSpecial) bool BrowserSettings::passwordUseEASCII() { - return config()->get("generator/EASCII", false).toBool(); + return config()->get("generator/EASCII", PasswordGenerator::DefaultEASCII).toBool(); } void BrowserSettings::setPasswordUseEASCII(bool useEASCII) @@ -261,7 +261,7 @@ void BrowserSettings::setPasswordUseEASCII(bool useEASCII) int BrowserSettings::passPhraseWordCount() { - return config()->get("generator/WordCount", 6).toInt(); + return config()->get("generator/WordCount", PassphraseGenerator::DefaultWordCount).toInt(); } void BrowserSettings::setPassPhraseWordCount(int wordCount) @@ -271,7 +271,7 @@ void BrowserSettings::setPassPhraseWordCount(int wordCount) QString BrowserSettings::passPhraseWordSeparator() { - return config()->get("generator/WordSeparator", " ").toString(); + return config()->get("generator/WordSeparator", PassphraseGenerator::DefaultSeparator).toString(); } void BrowserSettings::setPassPhraseWordSeparator(QString separator) @@ -291,7 +291,7 @@ void BrowserSettings::setGeneratorType(int type) bool BrowserSettings::passwordEveryGroup() { - return config()->get("generator/EnsureEvery", true).toBool(); + return config()->get("generator/EnsureEvery", PasswordGenerator::DefaultFromEveryGroup).toBool(); } void BrowserSettings::setPasswordEveryGroup(bool everyGroup) @@ -301,7 +301,7 @@ void BrowserSettings::setPasswordEveryGroup(bool everyGroup) bool BrowserSettings::passwordExcludeAlike() { - return config()->get("generator/ExcludeAlike", true).toBool(); + return config()->get("generator/ExcludeAlike", PasswordGenerator::DefaultLookAlike).toBool(); } void BrowserSettings::setPasswordExcludeAlike(bool excludeAlike) @@ -311,7 +311,7 @@ void BrowserSettings::setPasswordExcludeAlike(bool excludeAlike) int BrowserSettings::passwordLength() { - return config()->get("generator/Length", 20).toInt(); + return config()->get("generator/Length", PasswordGenerator::DefaultLength).toInt(); } void BrowserSettings::setPasswordLength(int length) diff --git a/src/core/FilePath.cpp b/src/core/FilePath.cpp index f694f548b..6b555075a 100644 --- a/src/core/FilePath.cpp +++ b/src/core/FilePath.cpp @@ -91,6 +91,11 @@ QString FilePath::pluginPath(const QString& name) return QString(); } +QString FilePath::wordlistPath(const QString& name) +{ + return m_instance->dataPath("wordlists/" + name); +} + QIcon FilePath::applicationIcon() { bool darkIcon = useDarkIcon(); diff --git a/src/core/FilePath.h b/src/core/FilePath.h index 2db496937..f84f84e0e 100644 --- a/src/core/FilePath.h +++ b/src/core/FilePath.h @@ -27,6 +27,7 @@ class FilePath public: QString dataPath(const QString& name); QString pluginPath(const QString& name); + QString wordlistPath(const QString& name); QIcon applicationIcon(); QIcon trayIconLocked(); QIcon trayIconUnlocked(); diff --git a/src/core/PassphraseGenerator.cpp b/src/core/PassphraseGenerator.cpp index 941ba5f38..2bc2be56d 100644 --- a/src/core/PassphraseGenerator.cpp +++ b/src/core/PassphraseGenerator.cpp @@ -24,9 +24,12 @@ #include "crypto/Random.h" #include "core/FilePath.h" +const QString PassphraseGenerator::DefaultSeparator = " "; +const QString PassphraseGenerator::DefaultWordList = "eff_large.wordlist"; + PassphraseGenerator::PassphraseGenerator() : m_wordCount(0) - , m_separator(' ') + , m_separator(PassphraseGenerator::DefaultSeparator) { } @@ -76,7 +79,7 @@ void PassphraseGenerator::setWordList(QString path) void PassphraseGenerator::setDefaultWordList() { - const QString path = filePath()->dataPath("wordlists/eff_large.wordlist"); + const QString path = filePath()->wordlistPath(PassphraseGenerator::DefaultWordList); setWordList(path); } diff --git a/src/core/PassphraseGenerator.h b/src/core/PassphraseGenerator.h index 7df4b4a74..4a489827d 100644 --- a/src/core/PassphraseGenerator.h +++ b/src/core/PassphraseGenerator.h @@ -37,6 +37,8 @@ public: QString generatePassphrase() const; static const int DefaultWordCount = 7; + static const QString DefaultSeparator; + static const QString DefaultWordList; private: int m_wordCount; diff --git a/src/core/PasswordGenerator.h b/src/core/PasswordGenerator.h index 0c13bac05..d1b2a0b39 100644 --- a/src/core/PasswordGenerator.h +++ b/src/core/PasswordGenerator.h @@ -42,7 +42,8 @@ public: enum GeneratorFlag { ExcludeLookAlike = 0x1, - CharFromEveryGroup = 0x2 + CharFromEveryGroup = 0x2, + DefaultFlags = ExcludeLookAlike | CharFromEveryGroup }; Q_DECLARE_FLAGS(GeneratorFlags, GeneratorFlag) @@ -60,6 +61,13 @@ public: int getbits() const; static const int DefaultLength = 16; + static const bool DefaultLower = (DefaultCharset & LowerLetters) != 0; + static const bool DefaultUpper = (DefaultCharset & UpperLetters) != 0; + static const bool DefaultNumbers = (DefaultCharset & Numbers) != 0; + static const bool DefaultSpecial = (DefaultCharset & SpecialCharacters) != 0; + static const bool DefaultEASCII = (DefaultCharset & EASCII) != 0; + static const bool DefaultLookAlike = (DefaultFlags & ExcludeLookAlike) != 0; + static const bool DefaultFromEveryGroup = (DefaultFlags & CharFromEveryGroup) != 0; private: QVector passwordGroups() const; diff --git a/src/gui/PasswordGeneratorWidget.cpp b/src/gui/PasswordGeneratorWidget.cpp index c9c10aa56..e6cb0a92d 100644 --- a/src/gui/PasswordGeneratorWidget.cpp +++ b/src/gui/PasswordGeneratorWidget.cpp @@ -68,9 +68,9 @@ PasswordGeneratorWidget::PasswordGeneratorWidget(QWidget* parent) } // set default separator to Space - m_ui->editWordSeparator->setText(" "); + m_ui->editWordSeparator->setText(PassphraseGenerator::DefaultSeparator); - QDir path(filePath()->dataPath("wordlists/")); + QDir path(filePath()->wordlistPath("")); QStringList files = path.entryList(QDir::Files); m_ui->comboBoxWordList->addItems(files); if (files.size() > 1) { @@ -93,19 +93,19 @@ PasswordGeneratorWidget::~PasswordGeneratorWidget() void PasswordGeneratorWidget::loadSettings() { // Password config - 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()); - m_ui->checkBoxExtASCII->setChecked(config()->get("generator/EASCII", false).toBool()); - m_ui->checkBoxExcludeAlike->setChecked(config()->get("generator/ExcludeAlike", true).toBool()); - m_ui->checkBoxEnsureEvery->setChecked(config()->get("generator/EnsureEvery", true).toBool()); + m_ui->checkBoxLower->setChecked(config()->get("generator/LowerCase", PasswordGenerator::DefaultLower).toBool()); + m_ui->checkBoxUpper->setChecked(config()->get("generator/UpperCase", PasswordGenerator::DefaultUpper).toBool()); + m_ui->checkBoxNumbers->setChecked(config()->get("generator/Numbers", PasswordGenerator::DefaultNumbers).toBool()); + m_ui->checkBoxSpecialChars->setChecked(config()->get("generator/SpecialChars", PasswordGenerator::DefaultSpecial).toBool()); + m_ui->checkBoxExtASCII->setChecked(config()->get("generator/EASCII", PasswordGenerator::DefaultEASCII).toBool()); + m_ui->checkBoxExcludeAlike->setChecked(config()->get("generator/ExcludeAlike", PasswordGenerator::DefaultLookAlike).toBool()); + m_ui->checkBoxEnsureEvery->setChecked(config()->get("generator/EnsureEvery", PasswordGenerator::DefaultFromEveryGroup).toBool()); m_ui->spinBoxLength->setValue(config()->get("generator/Length", PasswordGenerator::DefaultLength).toInt()); // Diceware config - m_ui->spinBoxWordCount->setValue(config()->get("generator/WordCount", 6).toInt()); - m_ui->editWordSeparator->setText(config()->get("generator/WordSeparator", " ").toString()); - m_ui->comboBoxWordList->setCurrentText(config()->get("generator/WordList", "eff_large.wordlist").toString()); + m_ui->spinBoxWordCount->setValue(config()->get("generator/WordCount", PassphraseGenerator::DefaultWordCount).toInt()); + m_ui->editWordSeparator->setText(config()->get("generator/WordSeparator", PassphraseGenerator::DefaultSeparator).toString()); + m_ui->comboBoxWordList->setCurrentText(config()->get("generator/WordList", PassphraseGenerator::DefaultWordList).toString()); // Password or diceware? m_ui->tabWidget->setCurrentIndex(config()->get("generator/Type", 0).toInt()); @@ -394,7 +394,7 @@ void PasswordGeneratorWidget::updateGenerator() m_dicewareGenerator->setWordCount(m_ui->spinBoxWordCount->value()); if (!m_ui->comboBoxWordList->currentText().isEmpty()) { - QString path = filePath()->dataPath("wordlists/" + m_ui->comboBoxWordList->currentText()); + QString path = filePath()->wordlistPath(m_ui->comboBoxWordList->currentText()); m_dicewareGenerator->setWordList(path); } m_dicewareGenerator->setWordSeparator(m_ui->editWordSeparator->text()); diff --git a/src/http/HttpPasswordGeneratorWidget.cpp b/src/http/HttpPasswordGeneratorWidget.cpp index b722a85f3..f08bc3d36 100644 --- a/src/http/HttpPasswordGeneratorWidget.cpp +++ b/src/http/HttpPasswordGeneratorWidget.cpp @@ -48,13 +48,14 @@ 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->checkBoxLower->setChecked(config()->get("Http/generator/LowerCase", PasswordGenerator::DefaultLower).toBool()); + m_ui->checkBoxUpper->setChecked(config()->get("Http/generator/UpperCase", PasswordGenerator::DefaultUpper).toBool()); + m_ui->checkBoxNumbers->setChecked(config()->get("Http/generator/Numbers", PasswordGenerator::DefaultNumbers).toBool()); + m_ui->checkBoxSpecialChars->setChecked(config()->get("Http/generator/SpecialChars", PasswordGenerator::DefaultSpecial).toBool()); + m_ui->checkBoxSpecialChars->setChecked(config()->get("Http/generator/EASCII", PasswordGenerator::DefaultEASCII).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->checkBoxExcludeAlike->setChecked(config()->get("Http/generator/ExcludeAlike", PasswordGenerator::DefaultLookAlike).toBool()); + m_ui->checkBoxEnsureEvery->setChecked(config()->get("Http/generator/EnsureEvery", PasswordGenerator::DefaultFromEveryGroup).toBool()); m_ui->spinBoxLength->setValue(config()->get("Http/generator/Length", PasswordGenerator::DefaultLength).toInt()); } @@ -65,6 +66,7 @@ void HttpPasswordGeneratorWidget::saveSettings() 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/EASCII", m_ui->checkBoxExtASCII->isChecked()); config()->set("Http/generator/ExcludeAlike", m_ui->checkBoxExcludeAlike->isChecked()); config()->set("Http/generator/EnsureEvery", m_ui->checkBoxEnsureEvery->isChecked()); @@ -120,6 +122,10 @@ PasswordGenerator::CharClasses HttpPasswordGeneratorWidget::charClasses() classes |= PasswordGenerator::SpecialCharacters; } + if (m_ui->checkBoxExtASCII->isChecked()) { + classes |= PasswordGenerator::EASCII; + } + return classes; } diff --git a/src/http/HttpPasswordGeneratorWidget.ui b/src/http/HttpPasswordGeneratorWidget.ui index 066b9c512..71df88730 100644 --- a/src/http/HttpPasswordGeneratorWidget.ui +++ b/src/http/HttpPasswordGeneratorWidget.ui @@ -142,6 +142,22 @@ + + + + Extended ASCII + + + Extended ASCII + + + true + + + optionButtons + + + diff --git a/src/http/HttpSettings.cpp b/src/http/HttpSettings.cpp index 60a35940c..7ff0dbaa4 100644 --- a/src/http/HttpSettings.cpp +++ b/src/http/HttpSettings.cpp @@ -145,7 +145,7 @@ void HttpSettings::setHttpPort(int port) bool HttpSettings::passwordUseNumbers() { - return config()->get("Http/generator/Numbers", true).toBool(); + return config()->get("Http/generator/Numbers", PasswordGenerator::DefaultNumbers).toBool(); } void HttpSettings::setPasswordUseNumbers(bool useNumbers) @@ -155,7 +155,7 @@ void HttpSettings::setPasswordUseNumbers(bool useNumbers) bool HttpSettings::passwordUseLowercase() { - return config()->get("Http/generator/LowerCase", true).toBool(); + return config()->get("Http/generator/LowerCase", PasswordGenerator::DefaultLower).toBool(); } void HttpSettings::setPasswordUseLowercase(bool useLowercase) @@ -165,7 +165,7 @@ void HttpSettings::setPasswordUseLowercase(bool useLowercase) bool HttpSettings::passwordUseUppercase() { - return config()->get("Http/generator/UpperCase", true).toBool(); + return config()->get("Http/generator/UpperCase", PasswordGenerator::DefaultUpper).toBool(); } void HttpSettings::setPasswordUseUppercase(bool useUppercase) @@ -175,7 +175,7 @@ void HttpSettings::setPasswordUseUppercase(bool useUppercase) bool HttpSettings::passwordUseSpecial() { - return config()->get("Http/generator/SpecialChars", false).toBool(); + return config()->get("Http/generator/SpecialChars", PasswordGenerator::DefaultSpecial).toBool(); } void HttpSettings::setPasswordUseSpecial(bool useSpecial) @@ -183,9 +183,19 @@ void HttpSettings::setPasswordUseSpecial(bool useSpecial) config()->set("Http/generator/SpecialChars", useSpecial); } +bool HttpSettings::passwordUseEASCII() +{ + return config()->get("Http/generator/EASCII", PasswordGenerator::DefaultEASCII).toBool(); +} + +void HttpSettings::setPasswordUseEASCII(bool useExtended) +{ + config()->set("Http/generator/EASCII", useExtended); +} + bool HttpSettings::passwordEveryGroup() { - return config()->get("Http/generator/EnsureEvery", true).toBool(); + return config()->get("Http/generator/EnsureEvery", PasswordGenerator::DefaultFromEveryGroup).toBool(); } void HttpSettings::setPasswordEveryGroup(bool everyGroup) @@ -195,7 +205,7 @@ void HttpSettings::setPasswordEveryGroup(bool everyGroup) bool HttpSettings::passwordExcludeAlike() { - return config()->get("Http/generator/ExcludeAlike", true).toBool(); + return config()->get("Http/generator/ExcludeAlike", PasswordGenerator::DefaultLookAlike).toBool(); } void HttpSettings::setPasswordExcludeAlike(bool excludeAlike) @@ -205,7 +215,7 @@ void HttpSettings::setPasswordExcludeAlike(bool excludeAlike) int HttpSettings::passwordLength() { - return config()->get("Http/generator/Length", 20).toInt(); + return config()->get("Http/generator/Length", PasswordGenerator::DefaultLength).toInt(); } void HttpSettings::setPasswordLength(int length) @@ -217,14 +227,21 @@ void HttpSettings::setPasswordLength(int length) PasswordGenerator::CharClasses HttpSettings::passwordCharClasses() { PasswordGenerator::CharClasses classes; - if (passwordUseLowercase()) + if (passwordUseLowercase()) { classes |= PasswordGenerator::LowerLetters; - if (passwordUseUppercase()) + } + if (passwordUseUppercase()) { classes |= PasswordGenerator::UpperLetters; - if (passwordUseNumbers()) + } + if (passwordUseNumbers()) { classes |= PasswordGenerator::Numbers; - if (passwordUseSpecial()) + } + if (passwordUseSpecial()) { classes |= PasswordGenerator::SpecialCharacters; + } + if (passwordUseEASCII()) { + classes |= PasswordGenerator::EASCII; + } return classes; } diff --git a/src/http/HttpSettings.h b/src/http/HttpSettings.h index a4aee1a63..63c2963cf 100644 --- a/src/http/HttpSettings.h +++ b/src/http/HttpSettings.h @@ -58,6 +58,8 @@ public: static void setPasswordUseUppercase(bool useUppercase); static bool passwordUseSpecial(); static void setPasswordUseSpecial(bool useSpecial); + static bool passwordUseEASCII(); + static void setPasswordUseEASCII(bool useExtended); static bool passwordEveryGroup(); static void setPasswordEveryGroup(bool everyGroup); static bool passwordExcludeAlike();