CppSecurity  1.1.1.0
C++ Security Library
Public Member Functions | List of all members
CppSecurity::PasswordHashing Class Referenceabstract

Password hashing interface. More...

#include <password_hashing.h>

Inheritance diagram for CppSecurity::PasswordHashing:
CppSecurity::Argon2dPasswordHashing CppSecurity::BcryptPasswordHashing CppSecurity::PBKDF2PasswordHashing CppSecurity::ScryptPasswordHashing CppSecurity::Argon2iPasswordHashing CppSecurity::Argon2idPasswordHashing

Public Member Functions

 PasswordHashing (size_t hash_length=32, size_t salt_length=32)
 Initialize password hashing with required parameters. More...
 
 PasswordHashing (const PasswordHashing &)=default
 
 PasswordHashing (PasswordHashing &&)=default
 
virtual ~PasswordHashing ()=default
 
PasswordHashingoperator= (const PasswordHashing &)=default
 
PasswordHashingoperator= (PasswordHashing &&)=default
 
size_t hash_length () const noexcept
 Get the strong password hash length. More...
 
size_t salt_length () const noexcept
 Get the unique password salt length. More...
 
virtual const std::string & name () const =0
 Get the password hashing algorithm name. More...
 
virtual std::string GenerateSalt () const
 Generate the unique password salt. More...
 
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. More...
 
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. More...
 
virtual std::string GenerateDigest (std::string_view password) const
 Generate the secure digest string for the given user password. More...
 
virtual std::string GenerateEncodedDigest (std::string_view password) const
 Generate the secure Base64 digest string for the given user password. More...
 
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. More...
 
virtual bool ValidateDigest (std::string_view password, std::string_view digest) const
 Validate the user password over the given secure digest string. More...
 
virtual bool ValidateEncodedDigest (std::string_view password, std::string_view digest) const
 Validate the user password over the given secure Base64 digest string. More...
 

Detailed Description

Password hashing interface.

Password hashing interface allows to generate strong password hash and salt to protect plain passwords from database access attack and validate the given password over the generated hash and salt.

https://en.wikipedia.org/wiki/Key_derivation_function

Thread-safe.

Definition at line 26 of file password_hashing.h.

Constructor & Destructor Documentation

◆ PasswordHashing() [1/3]

CppSecurity::PasswordHashing::PasswordHashing ( size_t  hash_length = 32,
size_t  salt_length = 32 
)

Initialize password hashing with required parameters.

Parameters
hash_length- Strong password hash length (default is 32)
salt_length- Unique password salt length (default is 32)

Definition at line 19 of file password_hashing.cpp.

◆ PasswordHashing() [2/3]

CppSecurity::PasswordHashing::PasswordHashing ( const PasswordHashing )
default

◆ PasswordHashing() [3/3]

CppSecurity::PasswordHashing::PasswordHashing ( PasswordHashing &&  )
default

◆ ~PasswordHashing()

virtual CppSecurity::PasswordHashing::~PasswordHashing ( )
virtualdefault

Member Function Documentation

◆ GenerateDigest()

std::string CppSecurity::PasswordHashing::GenerateDigest ( std::string_view  password) const
virtual

Generate the secure digest string for the given user password.

Parameters
password- User password
Returns
Secure digest string

Reimplemented in CppSecurity::BcryptPasswordHashing.

Definition at line 45 of file password_hashing.cpp.

◆ GenerateEncodedDigest()

std::string CppSecurity::PasswordHashing::GenerateEncodedDigest ( std::string_view  password) const
virtual

Generate the secure Base64 digest string for the given user password.

Parameters
password- User password
Returns
Secure Base64 digest string
Examples
password_hashing_argon2.cpp, password_hashing_bcrypt.cpp, password_hashing_pbkdf2.cpp, and password_hashing_scrypt.cpp.

Definition at line 51 of file password_hashing.cpp.

◆ GenerateHash()

virtual std::string CppSecurity::PasswordHashing::GenerateHash ( std::string_view  password,
std::string_view  salt 
) const
pure virtual

Generate the strong password hash for the given user password and unique salt.

Parameters
password- User password
salt- Unique password salt
Returns
Strong password hash

Implemented in CppSecurity::ScryptPasswordHashing, CppSecurity::PBKDF2PasswordHashing, CppSecurity::BcryptPasswordHashing, CppSecurity::Argon2idPasswordHashing, CppSecurity::Argon2iPasswordHashing, and CppSecurity::Argon2dPasswordHashing.

◆ GenerateHashAndSalt()

std::pair< std::string, std::string > CppSecurity::PasswordHashing::GenerateHashAndSalt ( std::string_view  password) const
virtual

Generate the strong password hash and unique salt for the given user password.

Parameters
password- User password
Returns
Strong password hash and unique salt

Definition at line 38 of file password_hashing.cpp.

◆ GenerateSalt()

std::string CppSecurity::PasswordHashing::GenerateSalt ( ) const
virtual

Generate the unique password salt.

Returns
Unique password salt

Reimplemented in CppSecurity::BcryptPasswordHashing.

Definition at line 31 of file password_hashing.cpp.

◆ hash_length()

size_t CppSecurity::PasswordHashing::hash_length ( ) const
inlinenoexcept

Get the strong password hash length.

Definition at line 43 of file password_hashing.h.

◆ name()

virtual const std::string& CppSecurity::PasswordHashing::name ( ) const
pure virtual

◆ operator=() [1/2]

PasswordHashing& CppSecurity::PasswordHashing::operator= ( const PasswordHashing )
default

◆ operator=() [2/2]

PasswordHashing& CppSecurity::PasswordHashing::operator= ( PasswordHashing &&  )
default

◆ salt_length()

size_t CppSecurity::PasswordHashing::salt_length ( ) const
inlinenoexcept

Get the unique password salt length.

Definition at line 45 of file password_hashing.h.

◆ Validate()

virtual bool CppSecurity::PasswordHashing::Validate ( std::string_view  password,
std::string_view  hash,
std::string_view  salt 
) const
pure virtual

Validate the user password over the given strong password hash and unique salt.

Parameters
password- User password
hash- Strong password hash
salt- Unique password salt
Returns
'true' if the given user password is valid, 'false' if the given user password is invalid

Implemented in CppSecurity::ScryptPasswordHashing, CppSecurity::PBKDF2PasswordHashing, CppSecurity::BcryptPasswordHashing, CppSecurity::Argon2idPasswordHashing, CppSecurity::Argon2iPasswordHashing, and CppSecurity::Argon2dPasswordHashing.

◆ ValidateDigest()

bool CppSecurity::PasswordHashing::ValidateDigest ( std::string_view  password,
std::string_view  digest 
) const
virtual

Validate the user password over the given secure digest string.

Parameters
password- User password
digest- Secure digest string
Returns
'true' if the given user password is valid, 'false' if the given user password is invalid

Reimplemented in CppSecurity::BcryptPasswordHashing.

Definition at line 57 of file password_hashing.cpp.

◆ ValidateEncodedDigest()

bool CppSecurity::PasswordHashing::ValidateEncodedDigest ( std::string_view  password,
std::string_view  digest 
) const
virtual

Validate the user password over the given secure Base64 digest string.

Parameters
password- User password
digest- Secure Base64 digest string
Returns
'true' if the given user password is valid, 'false' if the given user password is invalid
Examples
password_hashing_argon2.cpp, password_hashing_bcrypt.cpp, password_hashing_pbkdf2.cpp, and password_hashing_scrypt.cpp.

Definition at line 71 of file password_hashing.cpp.


The documentation for this class was generated from the following files: