Logo Pico-Framework A web-first embedded framework for C++
Loading...
Searching...
No Matches
PasswordHasher.h
Go to the documentation of this file.
1#pragma once
2
3#include <string>
4#include <vector>
5#include <cstdint> // For uint8_t
6
8public:
9
10 static constexpr int DEFAULT_ITERATIONS = 1000;
11 static constexpr size_t HASH_LENGTH = 32;
12
19
27 std::vector<uint8_t> hashPassword(const std::string& password, const std::vector<uint8_t>& salt);
28
37 bool verifyPassword(const std::string& password, const std::vector<uint8_t>& salt, const std::vector<uint8_t>& expectedHash);
38
45 std::string hashPasswordBase64(const std::string& password, const std::vector<uint8_t>& salt);
46
55 bool verifyPasswordBase64(const std::string& password, const std::vector<uint8_t>& salt, const std::string& expectedBase64Hash);
56
74 std::string hashAndEncode(const std::string& password);
75
90 bool verifyEncoded(const std::string& password, const std::string& combinedSaltAndHash);
91
103 static std::string toBase64(const std::vector<uint8_t>& data);
104
116 static std::vector<uint8_t> fromBase64(const std::string& base64);
117
128 static std::vector<uint8_t> generateSalt(size_t length);
129
130private:
132};
static constexpr size_t HASH_LENGTH
static constexpr int DEFAULT_ITERATIONS
static std::vector< uint8_t > generateSalt(size_t length)
PasswordHasher(int iterations=DEFAULT_ITERATIONS)
Constructs a PasswordHasher with the specified number of iterations.
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.
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.
bool verifyEncoded(const std::string &password, const std::string &combinedSaltAndHash)
static std::string toBase64(const std::vector< uint8_t > &data)
std::string hashAndEncode(const std::string &password)
std::vector< uint8_t > hashPassword(const std::string &password, const std::vector< uint8_t > &salt)
Hashes a password with the given salt.
std::string hashPasswordBase64(const std::string &password, const std::vector< uint8_t > &salt)
Hashes a password and encodes it in Base64 format.
static std::vector< uint8_t > fromBase64(const std::string &base64)