NAWA 0.9
Web Application Framework for C++
nawa::hashing::BcryptHashingEngine Class Reference

#include <nawa/hashing/HashingEngine/impl/BcryptHashingEngine.h>

Inherits nawa::hashing::HashingEngine.

Public Member Functions

virtual ~BcryptHashingEngine ()
 
 BcryptHashingEngine (int workFactor=10, std::string salt="")
 
std::string generateHash (std::string input) const override
 
bool verifyHash (std::string input, std::string hash) const override
 

Detailed Description

Hashing engine for password hashing using bcrypt. This engine class should not be used directly, but only through the corresponding Nawa::Crypto functions for password hashing.

Definition at line 35 of file BcryptHashingEngine.h.

Constructor & Destructor Documentation

◆ ~BcryptHashingEngine()

virtual nawa::hashing::BcryptHashingEngine::~BcryptHashingEngine ( )
virtual

◆ BcryptHashingEngine()

hashing::BcryptHashingEngine::BcryptHashingEngine ( int  workFactor = 10,
std::string  salt = "" 
)
explicit

Create a new generator object and set the work factor.

Parameters
workFactorThe work factor determines how much effort is needed in order to generate the salt. A higher work factor increases security of the hash, but it will also slow down the hash generation.
The work factor must be between (including) 4 and 31, if it is not, it will default to 12.
saltThe salt to use. Please leave this empty (default), a good random salt will be used then. If you are setting the salt, please note that at most BCRYPT_HASHSIZE characters of the given string will be used, the rest will be discarded.

Definition at line 41 of file BcryptHashingEngine.cpp.

Member Function Documentation

◆ generateHash()

std::string hashing::BcryptHashingEngine::generateHash ( std::string  input) const
overridevirtual

Generate a hash of the input string with the given salt or, if empty, with a random one based on the work factor.

This function might throw an exception with error code 10 (salt generation failed), or 11 (hash generation failed).

Parameters
inputThe input string to hash.
Returns
A bcrypt hash (60 characters) in the standard format, including WF and salt ("$2a$...").

Implements nawa::hashing::HashingEngine.

Definition at line 45 of file BcryptHashingEngine.cpp.

◆ verifyHash()

bool hashing::BcryptHashingEngine::verifyHash ( std::string  input,
std::string  hash 
) const
overridevirtual

Check if the given bcrypt hash in standard format (e.g., "$2a$..."), is a hash of the input string. This function is designed in a way that it should not be vulnerable to timing attacks.

Parameters
inputThe input string.
hashThe hash to verify.
Returns
True if it matches, false otherwise.

Implements nawa::hashing::HashingEngine.

Definition at line 66 of file BcryptHashingEngine.cpp.


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