2013-03-12 16:54:05 -04:00
|
|
|
/*
|
|
|
|
* Copyright (C) 2013 Felix Geyer <debfx@fobos.de>
|
2017-06-09 17:40:36 -04:00
|
|
|
* Copyright (C) 2017 KeePassXC Team <team@keepassxc.org>
|
2013-03-12 16:54:05 -04:00
|
|
|
*
|
|
|
|
* 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/>.
|
|
|
|
*/
|
|
|
|
|
|
|
|
#ifndef KEEPASSX_PASSWORDGENERATOR_H
|
|
|
|
#define KEEPASSX_PASSWORDGENERATOR_H
|
|
|
|
|
2013-10-03 09:18:16 -04:00
|
|
|
#include <QVector>
|
2013-03-12 16:54:05 -04:00
|
|
|
|
|
|
|
typedef QVector<QChar> PasswordGroup;
|
|
|
|
|
|
|
|
class PasswordGenerator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum CharClass
|
|
|
|
{
|
2018-06-10 22:37:09 -04:00
|
|
|
LowerLetters = (1 << 0),
|
|
|
|
UpperLetters = (1 << 1),
|
|
|
|
Numbers = (1 << 2),
|
|
|
|
Braces = (1 << 3),
|
|
|
|
Punctuation = (1 << 4),
|
|
|
|
Quotes = (1 << 5),
|
|
|
|
Dashes = (1 << 6),
|
|
|
|
Math = (1 << 7),
|
|
|
|
Logograms = (1 << 8),
|
|
|
|
SpecialCharacters = Braces | Punctuation | Quotes | Dashes | Math | Logograms,
|
|
|
|
EASCII = (1 << 9),
|
2018-03-31 16:01:30 -04:00
|
|
|
DefaultCharset = LowerLetters | UpperLetters | Numbers
|
2013-03-12 16:54:05 -04:00
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(CharClasses, CharClass)
|
|
|
|
|
|
|
|
enum GeneratorFlag
|
|
|
|
{
|
2018-06-10 22:37:09 -04:00
|
|
|
ExcludeLookAlike = (1 << 0),
|
|
|
|
CharFromEveryGroup = (1 << 1),
|
|
|
|
AdvancedMode = (1 << 2),
|
2018-03-31 16:01:30 -04:00
|
|
|
DefaultFlags = ExcludeLookAlike | CharFromEveryGroup
|
2013-03-12 16:54:05 -04:00
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(GeneratorFlags, GeneratorFlag)
|
|
|
|
|
2014-01-12 17:33:36 -05:00
|
|
|
public:
|
|
|
|
PasswordGenerator();
|
|
|
|
|
|
|
|
void setLength(int length);
|
|
|
|
void setCharClasses(const CharClasses& classes);
|
|
|
|
void setFlags(const GeneratorFlags& flags);
|
2019-11-16 11:51:56 -05:00
|
|
|
void setAdditionalChars(const QString& chars);
|
2018-06-10 22:37:09 -04:00
|
|
|
void setExcludedChars(const QString& chars);
|
2013-03-12 16:54:05 -04:00
|
|
|
|
2014-01-12 17:33:36 -05:00
|
|
|
bool isValid() const;
|
2013-03-12 16:54:05 -04:00
|
|
|
|
2014-01-12 17:33:36 -05:00
|
|
|
QString generatePassword() const;
|
2013-03-12 16:54:05 -04:00
|
|
|
|
2020-04-25 19:31:38 -04:00
|
|
|
static const int DefaultLength = 32;
|
2019-11-16 11:51:56 -05:00
|
|
|
static const char* DefaultAdditionalChars;
|
2018-06-10 22:37:09 -04:00
|
|
|
static const char* DefaultExcludedChars;
|
2017-09-06 09:14:41 -04:00
|
|
|
|
2014-01-14 15:00:27 -05:00
|
|
|
private:
|
2014-01-12 17:33:36 -05:00
|
|
|
QVector<PasswordGroup> passwordGroups() const;
|
|
|
|
int numCharClasses() const;
|
2013-03-12 16:54:05 -04:00
|
|
|
|
2014-01-12 17:33:36 -05:00
|
|
|
int m_length;
|
|
|
|
CharClasses m_classes;
|
|
|
|
GeneratorFlags m_flags;
|
2019-11-16 11:51:56 -05:00
|
|
|
QString m_additional;
|
2018-06-10 22:37:09 -04:00
|
|
|
QString m_excluded;
|
2013-03-12 16:54:05 -04:00
|
|
|
|
|
|
|
Q_DISABLE_COPY(PasswordGenerator)
|
|
|
|
};
|
|
|
|
|
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(PasswordGenerator::CharClasses)
|
|
|
|
|
|
|
|
Q_DECLARE_OPERATORS_FOR_FLAGS(PasswordGenerator::GeneratorFlags)
|
|
|
|
|
|
|
|
#endif // KEEPASSX_PASSWORDGENERATOR_H
|