CppSecurity  1.1.1.0
C++ Security Library
password_hashing.h
Go to the documentation of this file.
1 
9 #ifndef CPPSECURITY_PASSWORD_HASHING_H
10 #define CPPSECURITY_PASSWORD_HASHING_H
11 
12 #include "password.h"
13 
14 namespace CppSecurity {
15 
17 
27 {
28 public:
30 
34  PasswordHashing(size_t hash_length = 32, size_t salt_length = 32);
35  PasswordHashing(const PasswordHashing&) = default;
37  virtual ~PasswordHashing() = default;
38 
41 
43  size_t hash_length() const noexcept { return _hash_length; }
45  size_t salt_length() const noexcept { return _salt_length; }
46 
48  virtual const std::string& name() const = 0;
49 
51 
54  virtual std::string GenerateSalt() const;
55 
57 
61  virtual std::pair<std::string, std::string> GenerateHashAndSalt(std::string_view password) const;
62 
64 
69  virtual std::string GenerateHash(std::string_view password, std::string_view salt) const = 0;
70 
72 
76  virtual std::string GenerateDigest(std::string_view password) const;
77 
79 
83  virtual std::string GenerateEncodedDigest(std::string_view password) const;
84 
86 
92  virtual bool Validate(std::string_view password, std::string_view hash, std::string_view salt) const = 0;
93 
95 
100  virtual bool ValidateDigest(std::string_view password, std::string_view digest) const;
101 
103 
108  virtual bool ValidateEncodedDigest(std::string_view password, std::string_view digest) const;
109 
110 private:
111  size_t _hash_length;
112  size_t _salt_length;
113 };
114 
115 } // namespace CppSecurity
116 
117 #endif // CPPSECURITY_PASSWORD_HASHING_H
Password hashing interface.
size_t salt_length() const noexcept
Get the unique password salt length.
virtual std::string GenerateEncodedDigest(std::string_view password) const
Generate the secure Base64 digest string for the given user password.
PasswordHashing(PasswordHashing &&)=default
PasswordHashing & operator=(PasswordHashing &&)=default
virtual bool Validate(std::string_view password, std::string_view hash, std::string_view salt) const =0
Validate the user password over the given strong password hash and unique salt.
virtual std::string GenerateSalt() const
Generate the unique password salt.
virtual bool ValidateEncodedDigest(std::string_view password, std::string_view digest) const
Validate the user password over the given secure Base64 digest string.
virtual std::pair< std::string, std::string > GenerateHashAndSalt(std::string_view password) const
Generate the strong password hash and unique salt for the given user password.
virtual const std::string & name() const =0
Get the password hashing algorithm name.
PasswordHashing(size_t hash_length=32, size_t salt_length=32)
Initialize password hashing with required parameters.
size_t hash_length() const noexcept
Get the strong password hash length.
virtual std::string GenerateDigest(std::string_view password) const
Generate the secure digest string for the given user password.
virtual ~PasswordHashing()=default
PasswordHashing(const PasswordHashing &)=default
virtual bool ValidateDigest(std::string_view password, std::string_view digest) const
Validate the user password over the given secure digest string.
virtual std::string GenerateHash(std::string_view password, std::string_view salt) const =0
Generate the strong password hash for the given user password and unique salt.
PasswordHashing & operator=(const PasswordHashing &)=default
Password string definition.