blob: f877d2040fa2c02fc123d7ec0b1be97531a8b303 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
|
#include "../include/odhtdb/PasswordHash.hpp"
#include <argon2.h>
namespace odhtdb
{
OwnedByteArray hashPassword(const DataView &plainPassword, const DataView &salt)
{
OwnedByteArray result;
const uint32_t tCost = 2;
const uint32_t mCost = 1 << 16;
const uint32_t parallelism = 1;
result.data = new uint8_t[HASH_PASSWORD_LENGTH];
result.size = HASH_PASSWORD_LENGTH;
if(argon2i_hash_raw(tCost, mCost, parallelism, plainPassword.data, plainPassword.size, salt.data, salt.size, result.data, HASH_PASSWORD_LENGTH) != ARGON2_OK)
throw std::runtime_error("Failed to hash password");
return result;
}
}
|