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 <QFlags>
|
|
|
|
#include <QString>
|
|
|
|
#include <QVector>
|
2013-03-12 16:54:05 -04:00
|
|
|
|
|
|
|
typedef QVector<QChar> PasswordGroup;
|
|
|
|
|
|
|
|
class PasswordGenerator
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
enum CharClass
|
|
|
|
{
|
|
|
|
LowerLetters = 0x1,
|
|
|
|
UpperLetters = 0x2,
|
|
|
|
Numbers = 0x4,
|
2017-02-25 17:41:37 -05:00
|
|
|
SpecialCharacters = 0x8,
|
2018-01-22 07:47:20 -05:00
|
|
|
EASCII = 0x10,
|
|
|
|
DefaultCharset = LowerLetters | UpperLetters | Numbers
|
2013-03-12 16:54:05 -04:00
|
|
|
};
|
|
|
|
Q_DECLARE_FLAGS(CharClasses, CharClass)
|
|
|
|
|
|
|
|
enum GeneratorFlag
|
|
|
|
{
|
|
|
|
ExcludeLookAlike = 0x1,
|
2018-02-05 06:31:13 -05:00
|
|
|
CharFromEveryGroup = 0x2,
|
|
|
|
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();
|
|
|
|
|
2016-11-23 21:59:24 -05:00
|
|
|
double calculateEntropy(QString password);
|
2014-01-12 17:33:36 -05:00
|
|
|
void setLength(int length);
|
|
|
|
void setCharClasses(const CharClasses& classes);
|
|
|
|
void setFlags(const GeneratorFlags& flags);
|
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;
|
2014-03-22 21:13:27 -04:00
|
|
|
int getbits() const;
|
2013-03-12 16:54:05 -04:00
|
|
|
|
2017-09-06 09:14:41 -04:00
|
|
|
static const int DefaultLength = 16;
|
2018-02-05 19:17:36 -05:00
|
|
|
static constexpr bool DefaultLower = (DefaultCharset & LowerLetters) != 0;
|
|
|
|
static constexpr bool DefaultUpper = (DefaultCharset & UpperLetters) != 0;
|
|
|
|
static constexpr bool DefaultNumbers = (DefaultCharset & Numbers) != 0;
|
|
|
|
static constexpr bool DefaultSpecial = (DefaultCharset & SpecialCharacters) != 0;
|
|
|
|
static constexpr bool DefaultEASCII = (DefaultCharset & EASCII) != 0;
|
|
|
|
static constexpr bool DefaultLookAlike = (DefaultFlags & ExcludeLookAlike) != 0;
|
|
|
|
static constexpr bool DefaultFromEveryGroup = (DefaultFlags & CharFromEveryGroup) != 0;
|
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;
|
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
|