diff options
author | Aleksi Lindeman <0xdec05eba@gmail.com> | 2018-04-14 19:45:15 +0200 |
---|---|---|
committer | Aleksi Lindeman <0xdec05eba@gmail.com> | 2018-04-14 19:45:24 +0200 |
commit | 6e4d46f8cf911b82a10e8cd25b65fcc421bbc712 (patch) | |
tree | 3d6ee838990389d920df934e20aea1700052ce74 /src/PasswordHash.cpp | |
parent | 9c22be3516d5067b98b06271e2f3545713ff6099 (diff) |
Store database storage to files, also loading
Diffstat (limited to 'src/PasswordHash.cpp')
-rw-r--r-- | src/PasswordHash.cpp | 23 |
1 files changed, 23 insertions, 0 deletions
diff --git a/src/PasswordHash.cpp b/src/PasswordHash.cpp new file mode 100644 index 0000000..f6d3713 --- /dev/null +++ b/src/PasswordHash.cpp @@ -0,0 +1,23 @@ +#include "../include/odhtdb/PasswordHash.hpp" +#include <argon2.h> + +namespace odhtdb +{ + OwnedMemory hashPassword(const DataView &plainPassword, const DataView &salt) + { + OwnedMemory result; + + const uint32_t tCost = 2; + const uint32_t mCost = 1 << 16; + const uint32_t parallelism = 1; + const uint32_t HASHLEN = 32; + + result.data = new uint8_t[HASHLEN]; + result.size = HASHLEN; + + if(argon2i_hash_raw(tCost, mCost, parallelism, plainPassword.data, plainPassword.size, salt.data, salt.size, result.data, HASHLEN) != ARGON2_OK) + throw std::runtime_error("Failed to hash password"); + + return result; + } +} |