ORE Studio 0.0.4
Loading...
Searching...
No Matches
Static Public Member Functions | List of all members
password_hasher Class Reference

Manages password hashing and verification using the scrypt algorithm. More...

#include <password_hasher.hpp>

Collaboration diagram for password_hasher:
Collaboration graph

Static Public Member Functions

static std::string hash (const std::string &password)
 Creates a password hash from the given password.
 
static bool verify (const std::string &password, const std::string &hash)
 Verifies a password against a stored hash.
 

Detailed Description

Manages password hashing and verification using the scrypt algorithm.

The password_hasher class provides static methods to securely hash passwords and verify them against stored hashes. It uses the scrypt key derivation function from OpenSSL to generate and validate password hashes, ensuring strong security through configurable CPU/memory cost parameters.

Member Function Documentation

◆ hash()

std::string hash ( const std::string &  password)
static

Creates a password hash from the given password.

Generates a secure hash of the provided password using the scrypt algorithm with predefined parameters (CPU/memory cost, block size, and parallelisation). The hash is formatted as a string containing the algorithm identifier, parameters, salt, and hash, all Base64-encoded.

Parameters
passwordThe plaintext password to hash.
Returns
A string containing the formatted hash (e.g., "$scrypt$ln=14,r=8,p=1$<salt>$<hash>").
Exceptions
std::invalid_argumentIf the password is empty.
std::runtime_errorIf hash generation fails (e.g., due to random salt generation or scrypt errors).
Here is the caller graph for this function:

◆ verify()

bool verify ( const std::string &  password,
const std::string &  hash 
)
static

Verifies a password against a stored hash.

Checks if the provided password matches the given hash by recomputing the hash with the same salt and scrypt parameters extracted from the hash string. Uses constant-time comparison to prevent timing attacks.

Parameters
passwordThe plaintext password to verify.
hashThe stored hash string to verify against (e.g., "$scrypt$ln=14,r=8,p=1$<salt>$<hash>").
Returns
True if the password matches the hash, false otherwise.