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

'bcrypt' password hashing algorithm More...

#include <password_hashing_bcrypt.h>

Inheritance diagram for CppSecurity::BcryptPasswordHashing:
CppSecurity::PasswordHashing

Public Member Functions

 BcryptPasswordHashing (size_t workfactor=4)
 Initialize 'bcrypt' password hashing with required parameters. More...
 
 BcryptPasswordHashing (const BcryptPasswordHashing &)=default
 
 BcryptPasswordHashing (BcryptPasswordHashing &&)=default
 
 ~BcryptPasswordHashing ()=default
 
BcryptPasswordHashingoperator= (const BcryptPasswordHashing &)=default
 
BcryptPasswordHashingoperator= (BcryptPasswordHashing &&)=default
 
size_t workfactor () const noexcept
 Get the work factor. More...
 
const std::string & name () const override
 Get the password hashing algorithm name. More...
 
std::string GenerateSalt () const override
 Generate the unique password salt. More...
 
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. More...
 
std::string GenerateDigest (std::string_view password) const override
 Generate the secure digest string for the given user password. More...
 
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. More...
 
bool ValidateDigest (std::string_view password, std::string_view digest) const override
 Validate the user password over the given secure digest string. More...
 
- Public Member Functions inherited from CppSecurity::PasswordHashing
 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 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 GenerateEncodedDigest (std::string_view password) const
 Generate the secure Base64 digest string for the given user password. 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

'bcrypt' password hashing algorithm

'bcrypt' is a password hashing function designed by Niels Provos and David Mazieres, based on the Blowfish cipher, and presented at USENIX in 1999. Besides incorporating a salt to protect against rainbow table attacks, bcrypt is an adaptive function: over time, the iteration count can be increased to make it slower, so it remains resistant to brute-force search attacks even with increasing computation power.

The bcrypt function is the default password hash algorithm for OpenBSD and other systems including some Linux distributions such as SUSE Linux.

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

Thread-safe.

Examples
password_hashing_bcrypt.cpp.

Definition at line 31 of file password_hashing_bcrypt.h.

Constructor & Destructor Documentation

◆ BcryptPasswordHashing() [1/3]

CppSecurity::BcryptPasswordHashing::BcryptPasswordHashing ( size_t  workfactor = 4)

Initialize 'bcrypt' password hashing with required parameters.

Parameters
workfactor- Work factor (default is 4)

Definition at line 19 of file password_hashing_bcrypt.cpp.

◆ BcryptPasswordHashing() [2/3]

CppSecurity::BcryptPasswordHashing::BcryptPasswordHashing ( const BcryptPasswordHashing )
default

◆ BcryptPasswordHashing() [3/3]

CppSecurity::BcryptPasswordHashing::BcryptPasswordHashing ( BcryptPasswordHashing &&  )
default

◆ ~BcryptPasswordHashing()

CppSecurity::BcryptPasswordHashing::~BcryptPasswordHashing ( )
default

Member Function Documentation

◆ GenerateDigest()

std::string CppSecurity::BcryptPasswordHashing::GenerateDigest ( std::string_view  password) const
overridevirtual

Generate the secure digest string for the given user password.

Parameters
password- User password
Returns
Secure digest string

Reimplemented from CppSecurity::PasswordHashing.

Definition at line 42 of file password_hashing_bcrypt.cpp.

◆ GenerateHash()

std::string CppSecurity::BcryptPasswordHashing::GenerateHash ( std::string_view  password,
std::string_view  salt 
) const
overridevirtual

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

Implements CppSecurity::PasswordHashing.

Definition at line 33 of file password_hashing_bcrypt.cpp.

◆ GenerateSalt()

std::string CppSecurity::BcryptPasswordHashing::GenerateSalt ( ) const
overridevirtual

Generate the unique password salt.

Returns
Unique password salt

Reimplemented from CppSecurity::PasswordHashing.

Definition at line 25 of file password_hashing_bcrypt.cpp.

◆ name()

const std::string& CppSecurity::BcryptPasswordHashing::name ( ) const
inlineoverridevirtual

Get the password hashing algorithm name.

Implements CppSecurity::PasswordHashing.

Definition at line 50 of file password_hashing_bcrypt.h.

◆ operator=() [1/2]

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

◆ operator=() [2/2]

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

◆ Validate()

bool CppSecurity::BcryptPasswordHashing::Validate ( std::string_view  password,
std::string_view  hash,
std::string_view  salt 
) const
overridevirtual

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

Implements CppSecurity::PasswordHashing.

Definition at line 48 of file password_hashing_bcrypt.cpp.

◆ ValidateDigest()

bool CppSecurity::BcryptPasswordHashing::ValidateDigest ( std::string_view  password,
std::string_view  digest 
) const
overridevirtual

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 from CppSecurity::PasswordHashing.

Definition at line 59 of file password_hashing_bcrypt.cpp.

◆ workfactor()

size_t CppSecurity::BcryptPasswordHashing::workfactor ( ) const
inlinenoexcept

Get the work factor.

Definition at line 47 of file password_hashing_bcrypt.h.


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