From e4b6d2987db3d6c20343ffb00cb68cf2a85c45ca Mon Sep 17 00:00:00 2001 From: EntireTwix Date: Tue, 13 Apr 2021 09:07:30 -0700 Subject: [PATCH] :bug: hash deterministic --- include/bank.hpp | 10 +++++----- include/user.hpp | 4 ++-- 2 files changed, 7 insertions(+), 7 deletions(-) diff --git a/include/bank.hpp b/include/bank.hpp index 6421087..a53cd10 100644 --- a/include/bank.hpp +++ b/include/bank.hpp @@ -54,7 +54,7 @@ public: bool DelUser(const std::string &name, const std::string &attempt) { std::unique_lock lock{size_lock}; - return users.erase_if(name, [&attempt](const User &u) { return (XXH64(attempt.data(), attempt.size(), 0) == u.password); }); + return users.erase_if(name, [&attempt](const User &u) { return (XXH64(attempt.data(), attempt.size(), 1) == u.password); }); } bool AdminDelUser(const std::string &name, const std::string &attempt) { @@ -75,7 +75,7 @@ public: bool state = false; std::shared_lock lock{send_funds_l}; //because SendFunds requires 3 locking operations users.modify_if(a_name, [&state, amount, &attempt](User &a) { - if (state = (a.balance >= amount) && (a.password == XXH64(attempt.data(), attempt.size(), 0))) + if (state = (a.balance >= amount) && (a.password == XXH64(attempt.data(), attempt.size(), 1))) { a.balance -= amount; } @@ -126,7 +126,7 @@ public: { int_fast8_t res = -1; users.if_contains(name, [&res, &attempt](const User &u) { - res = u.password == XXH64(attempt.data(), attempt.size(), 0); + res = u.password == XXH64(attempt.data(), attempt.size(), 1); }); return res; } @@ -134,10 +134,10 @@ public: { int_fast8_t res = -1; users.modify_if(name, [&res, &attempt, &new_pass](User &u) { - res = (u.password == XXH64(attempt.data(), attempt.size(), 0)); + res = (u.password == XXH64(attempt.data(), attempt.size(), 1)); if (res) { - u.password = XXH64(new_pass.data(), new_pass.size(), 0); + u.password = XXH64(new_pass.data(), new_pass.size(), 1); } }); return res; diff --git a/include/user.hpp b/include/user.hpp index a54d883..1c1a02f 100644 --- a/include/user.hpp +++ b/include/user.hpp @@ -12,7 +12,7 @@ struct User * * @param init_pass initial password */ - User(std::string &&init_pass) : password(XXH64(init_pass.data(), init_pass.size(), 0)) {} + User(std::string &&init_pass) : password(XXH64(init_pass.data(), init_pass.size(), 1)) {} /** * @brief User Constructor for admins @@ -20,7 +20,7 @@ struct User * @param init_bal initial balance * @param init_pass initial password */ - User(uint_fast32_t init_bal, std::string &&init_pass) : balance(init_bal), password(XXH64(init_pass.data(), init_pass.size(), 0)) {} + User(uint_fast32_t init_bal, std::string &&init_pass) : balance(init_bal), password(XXH64(init_pass.data(), init_pass.size(), 1)) {} Json::Value Serialize() const {