CppSecurity  1.1.1.0
C++ Security Library
password_generator.h
Go to the documentation of this file.
1 
9 #ifndef CPPSECURITY_PASSWORD_GENERATOR_H
10 #define CPPSECURITY_PASSWORD_GENERATOR_H
11 
12 #include "password.h"
13 
14 #include "common/flags.h"
15 
16 namespace CppSecurity {
17 
19 enum class PasswordFlags
20 {
21  none = 0x0,
22  lower = 0x1,
23  upper = 0x2,
24  digits = 0x4,
25  symbols = 0x8,
26 };
27 
29 
34 template <class TOutputStream>
35 TOutputStream& operator<<(TOutputStream& stream, PasswordFlags flags);
36 
37 } // namespace CppSecurity
38 
39 // Register enum as flags to enable AND/OR/XOR logical operators with enum values!
41 
42 namespace CppSecurity {
43 
45 
52 {
53 public:
55 
62  virtual ~PasswordGenerator() = default;
63 
66 
68  size_t length() const noexcept { return _length; }
70  PasswordFlags flags() const noexcept { return _flags; }
71 
73 
76  virtual std::password Generate() const;
77 
79 
83  virtual bool Validate(std::string_view password) const;
84 
85 private:
86  size_t _length;
87  PasswordFlags _flags;
88 };
89 
92 } // namespace CppSecurity
93 
94 #include "password_generator.inl"
95 
96 #endif // CPPSECURITY_PASSWORD_GENERATOR_H
PasswordGenerator & operator=(PasswordGenerator &&)=default
virtual std::password Generate() const
Generate the strong password with the current password requirements.
size_t length() const noexcept
Get the password length.
PasswordGenerator(size_t length=12, PasswordFlags flags=PasswordFlags::lower|PasswordFlags::upper|PasswordFlags::digits)
Initialize password generator with required parameters.
PasswordGenerator & operator=(const PasswordGenerator &)=default
virtual ~PasswordGenerator()=default
PasswordGenerator(PasswordGenerator &&)=default
virtual bool Validate(std::string_view password) const
Validate the given password with the current password requirements.
PasswordGenerator(const PasswordGenerator &)=default
PasswordFlags flags() const noexcept
Get the password flags.
Password string.
Definition: password.h:53
TOutputStream & operator<<(TOutputStream &stream, CipherAlgorithm algorithm)
Definition: cipher.inl:12
PasswordFlags
Password flags.
@ upper
Password must contain alphabet characters in upper case (A-Z)
@ none
Empty password flags.
@ symbols
Password must contain punctuation symbols (!"#$%&'()*+,-./:;<=>?@[]^_`{|}~)
@ lower
Password must contain alphabet characters in lower case (a-z)
@ digits
Password must contain digits (0-9)
Password string definition.
Password generator inline implementation.