add default charset when not specified

explicitly state the wordcount default value
This commit is contained in:
thez3ro 2018-01-22 13:47:20 +01:00
parent e9612ee9e6
commit e57a2e0fa9
No known key found for this signature in database
GPG Key ID: F628F9E41DD7C073
7 changed files with 16 additions and 12 deletions

View File

@ -133,8 +133,7 @@ int Add::execute(QStringList arguments)
passwordGenerator.setLength(passwordLength.toInt()); passwordGenerator.setLength(passwordLength.toInt());
} }
passwordGenerator.setCharClasses(PasswordGenerator::LowerLetters | PasswordGenerator::UpperLetters | passwordGenerator.setCharClasses(PasswordGenerator::DefaultCharset);
PasswordGenerator::Numbers);
QString password = passwordGenerator.generatePassword(); QString password = passwordGenerator.generatePassword();
entry->setPassword(password); entry->setPassword(password);
} }

View File

@ -149,8 +149,7 @@ int Edit::execute(QStringList arguments)
passwordGenerator.setLength(passwordLength.toInt()); passwordGenerator.setLength(passwordLength.toInt());
} }
passwordGenerator.setCharClasses(PasswordGenerator::LowerLetters | PasswordGenerator::UpperLetters | passwordGenerator.setCharClasses(PasswordGenerator::DefaultCharset);
PasswordGenerator::Numbers);
QString password = passwordGenerator.generatePassword(); QString password = passwordGenerator.generatePassword();
entry->setPassword(password); entry->setPassword(password);
} }

View File

@ -96,12 +96,7 @@ int PassGen::execute(QStringList arguments)
classes |= PasswordGenerator::EASCII; classes |= PasswordGenerator::EASCII;
} }
if (classes == 0x0) { passwordGenerator.setCharClasses(classes);
passwordGenerator.setCharClasses(PasswordGenerator::LowerLetters | PasswordGenerator::UpperLetters |
PasswordGenerator::Numbers);
} else {
passwordGenerator.setCharClasses(classes);
}
if (!passwordGenerator.isValid()) { if (!passwordGenerator.isValid()) {
outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli passgen"); outputTextStream << parser.helpText().replace("keepassxc-cli", "keepassxc-cli passgen");

View File

@ -48,7 +48,7 @@ void PassphraseGenerator::setWordCount(int wordCount)
m_wordCount = wordCount; m_wordCount = wordCount;
} else { } else {
// safe default if something goes wrong // safe default if something goes wrong
m_wordCount = 7; m_wordCount = DefaultWordCount;
} }
} }

View File

@ -36,6 +36,8 @@ public:
QString generatePassphrase() const; QString generatePassphrase() const;
static const int DefaultWordCount = 7;
private: private:
int m_wordCount; int m_wordCount;
QString m_separator; QString m_separator;

View File

@ -35,11 +35,19 @@ double PasswordGenerator::calculateEntropy(QString password)
void PasswordGenerator::setLength(int length) void PasswordGenerator::setLength(int length)
{ {
if (length <= 0) {
m_length = DefaultLength;
return;
}
m_length = length; m_length = length;
} }
void PasswordGenerator::setCharClasses(const CharClasses& classes) void PasswordGenerator::setCharClasses(const CharClasses& classes)
{ {
if (classes == 0) {
m_classes = DefaultCharset;
return;
}
m_classes = classes; m_classes = classes;
} }

View File

@ -34,7 +34,8 @@ public:
UpperLetters = 0x2, UpperLetters = 0x2,
Numbers = 0x4, Numbers = 0x4,
SpecialCharacters = 0x8, SpecialCharacters = 0x8,
EASCII = 0x10 EASCII = 0x10,
DefaultCharset = LowerLetters | UpperLetters | Numbers
}; };
Q_DECLARE_FLAGS(CharClasses, CharClass) Q_DECLARE_FLAGS(CharClasses, CharClass)