Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
PasswordHasher Class Reference

#include <PasswordHasher.h>

+ Collaboration diagram for PasswordHasher:

Public Member Functions

 PasswordHasher (int iterations=DEFAULT_ITERATIONS)
 Constructs a PasswordHasher with the specified number of iterations.
 
std::vector< uint8_t > hashPassword (const std::string &password, const std::vector< uint8_t > &salt)
 Hashes a password with the given salt.
 
bool verifyPassword (const std::string &password, const std::vector< uint8_t > &salt, const std::vector< uint8_t > &expectedHash)
 Verifies a password against an expected hash using the provided salt.
 
std::string hashPasswordBase64 (const std::string &password, const std::vector< uint8_t > &salt)
 Hashes a password and encodes it in Base64 format.
 
bool verifyPasswordBase64 (const std::string &password, const std::vector< uint8_t > &salt, const std::string &expectedBase64Hash)
 Verifies a password against an expected Base64 encoded hash using the provided salt.
 
std::string hashAndEncode (const std::string &password)
 
bool verifyEncoded (const std::string &password, const std::string &combinedSaltAndHash)
 

Static Public Member Functions

static std::string toBase64 (const std::vector< uint8_t > &data)
 
static std::vector< uint8_t > fromBase64 (const std::string &base64)
 
static std::vector< uint8_t > generateSalt (size_t length)
 

Static Public Attributes

static constexpr int DEFAULT_ITERATIONS = 1000
 
static constexpr size_t HASH_LENGTH = 32
 

Private Attributes

int iterations
 

Detailed Description

Constructor & Destructor Documentation

◆ PasswordHasher()

PasswordHasher::PasswordHasher ( int  iterations = DEFAULT_ITERATIONS)
Parameters
iterationsNumber of iterations for the hashing algorithm. Default is 1,000.

Member Function Documentation

◆ fromBase64()

static std::vector< uint8_t > PasswordHasher::fromBase64 ( const std::string &  base64)
static

◆ generateSalt()

static std::vector< uint8_t > PasswordHasher::generateSalt ( size_t  length)
static

◆ hashAndEncode()

std::string PasswordHasher::hashAndEncode ( const std::string &  password)

◆ hashPassword()

std::vector< uint8_t > PasswordHasher::hashPassword ( const std::string &  password,
const std::vector< uint8_t > &  salt 
)
Parameters
passwordThe password to hash.
saltThe salt to use for hashing.
Returns
A vector containing the hashed password.
Examples
/home/runner/work/pico-framework-docs/pico-framework-docs/pico-framework/framework/include/framework/PasswordHasher.h.

◆ hashPasswordBase64()

std::string PasswordHasher::hashPasswordBase64 ( const std::string &  password,
const std::vector< uint8_t > &  salt 
)
Parameters
passwordThe password to hash.
Returns
A Base64 encoded string of the hashed password.
Examples
/home/runner/work/pico-framework-docs/pico-framework-docs/pico-framework/framework/include/framework/PasswordHasher.h.

◆ toBase64()

static std::string PasswordHasher::toBase64 ( const std::vector< uint8_t > &  data)
static

◆ verifyEncoded()

bool PasswordHasher::verifyEncoded ( const std::string &  password,
const std::string &  combinedSaltAndHash 
)

◆ verifyPassword()

bool PasswordHasher::verifyPassword ( const std::string &  password,
const std::vector< uint8_t > &  salt,
const std::vector< uint8_t > &  expectedHash 
)
Parameters
passwordThe password to verify.
saltThe salt used for hashing.
expectedHashThe expected hash to compare against.
Returns
true if the password matches the expected hash, false otherwise.
Examples
/home/runner/work/pico-framework-docs/pico-framework-docs/pico-framework/framework/include/framework/PasswordHasher.h.

◆ verifyPasswordBase64()

bool PasswordHasher::verifyPasswordBase64 ( const std::string &  password,
const std::vector< uint8_t > &  salt,
const std::string &  expectedBase64Hash 
)
Parameters
passwordThe password to verify.
saltThe salt used for hashing.
expectedBase64HashThe expected Base64 encoded hash to compare against.
Returns
true if the password matches the expected Base64 hash, false otherwise.
Examples
/home/runner/work/pico-framework-docs/pico-framework-docs/pico-framework/framework/include/framework/PasswordHasher.h.

Member Data Documentation

◆ DEFAULT_ITERATIONS

constexpr int PasswordHasher::DEFAULT_ITERATIONS = 1000
staticconstexpr

◆ HASH_LENGTH

constexpr size_t PasswordHasher::HASH_LENGTH = 32
staticconstexpr

◆ iterations


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