25#include <libbcrypt/bcrypt.h>
32struct hashing::BcryptHashingEngine::Data {
36 Data(
int workFactor,
string salt) : workFactor(workFactor), salt(std::move(salt)) {}
42 data = make_unique<Data>(workFactor, std::move(salt));
45std::string hashing::BcryptHashingEngine::generateHash(std::string input)
const {
46 char bcsalt[BCRYPT_HASHSIZE];
47 char hash[BCRYPT_HASHSIZE];
50 if (!data->salt.empty()) {
51 string salt_res = data->salt;
52 salt_res.resize(BCRYPT_HASHSIZE,
'\0');
53 memcpy(hash, salt_res.c_str(), BCRYPT_HASHSIZE);
54 }
else if (bcrypt_gensalt(data->workFactor, bcsalt) != 0) {
56 "Could not generate a salt (unknown bcrypt failure).");
59 if (bcrypt_hashpw(input.c_str(), bcsalt, hash) != 0) {
61 "Could not hash this password (unknown bcrypt failure).");
68 int ret = bcrypt_checkpw(input.c_str(), hash.c_str());
Hashing engine for password hashing using Argon2.
Exception class that can be used by apps to catch errors resulting from nawa function calls.
bool verifyHash(std::string input, std::string hash) const override
#define NAWA_DEFAULT_DESTRUCTOR_IMPL_WITH_NS(Namespace, Class)