CppSecurity  1.1.1.0
C++ Security Library
password_hashing_pbkdf2.h
Go to the documentation of this file.
1 
9 #ifndef CPPSECURITY_PASSWORD_HASHING_PBKDF2_H
10 #define CPPSECURITY_PASSWORD_HASHING_PBKDF2_H
11 
12 #include "password_hashing.h"
13 
14 namespace CppSecurity {
15 
17 enum class PBKDF2
18 {
19  HMAC_SHA1,
20  HMAC_SHA256,
22 };
23 
25 
30 template <class TOutputStream>
31 TOutputStream& operator<<(TOutputStream& stream, PBKDF2 algorithm);
32 
34 
48 {
49 public:
51 
61 
64 
66  PBKDF2 algorithm() const noexcept { return _algorithm; }
68  size_t iterations() const noexcept { return _iterations; }
69 
70  // Implementation of PasswordHashing
71  const std::string& name() const override { return _name; }
72  std::string GenerateHash(std::string_view password, std::string_view salt) const override;
73  bool Validate(std::string_view password, std::string_view hash, std::string_view salt) const override;
74 
75 private:
76  static std::string _name;
77  PBKDF2 _algorithm;
78  size_t _iterations;
79 };
80 
83 } // namespace CppSecurity
84 
86 
87 #endif // CPPSECURITY_PASSWORD_HASHING_PBKDF2_H
'PBKDF2' password hashing algorithm
const std::string & name() const override
Get the password hashing algorithm name.
PBKDF2PasswordHashing & operator=(const PBKDF2PasswordHashing &)=default
PBKDF2PasswordHashing(PBKDF2PasswordHashing &&)=default
PBKDF2PasswordHashing(size_t hash_length=32, size_t salt_length=32, PBKDF2 algorithm=PBKDF2::HMAC_SHA512, size_t iterations=1000)
Initialize 'PBKDF2' password hashing with required parameters.
size_t iterations() const noexcept
Get the count of 'PBKDF2' iterations.
PBKDF2 algorithm() const noexcept
Get the 'PBKDF2' algorithm.
PBKDF2PasswordHashing & operator=(PBKDF2PasswordHashing &&)=default
PBKDF2PasswordHashing(const PBKDF2PasswordHashing &)=default
std::string GenerateHash(std::string_view password, std::string_view salt) const override
Generate the strong password hash for the given user password and unique salt.
bool Validate(std::string_view password, std::string_view hash, std::string_view salt) const override
Validate the user password over the given strong password hash and unique salt.
Password hashing interface.
size_t salt_length() const noexcept
Get the unique password salt length.
size_t hash_length() const noexcept
Get the strong password hash length.
TOutputStream & operator<<(TOutputStream &stream, CipherAlgorithm algorithm)
Definition: cipher.inl:12
PBKDF2
'PBKDF2' algorithm
@ HMAC_SHA1
HMAC-SHA1.
@ HMAC_SHA256
HMAC-SHA256.
@ HMAC_SHA512
HMAC-SHA512.
Password hashing interface definition.
'PBKDF2' password hashing algorithm inline implementation