diff --git a/include/bank.hpp b/include/bank.hpp index fa3f20b..51e9320 100644 --- a/include/bank.hpp +++ b/include/bank.hpp @@ -2,6 +2,7 @@ #include #include #include +#include #include "parallel-hashmap/parallel_hashmap/phmap.h" #include "user.hpp" @@ -53,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 (std::hash{}(attempt) == u.password); }); + return users.erase_if(name, [&attempt](const User &u) { return (XXH64(attempt.data(), attempt.size(), 0) == u.password); }); } bool AdminDelUser(const std::string &name, const std::string &attempt) { @@ -74,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 == std::hash{}(attempt)), state) + if (state = (a.balance >= amount) && (a.password == XXH64(attempt.data(), attempt.size(), 0)), state) { a.balance -= amount; } @@ -125,7 +126,7 @@ public: { int_fast8_t res = -1; users.if_contains(name, [&res, &attempt](const User &u) { - res = u.password == std::hash{}(attempt); + res = u.password == XXH64(attempt.data(), attempt.size(), 0); }); return res; } @@ -133,7 +134,7 @@ public: { int_fast8_t res = -1; users.modify_if(name, [&res, &attempt, &new_pass](User &u) { - res = (u.password == std::hash{}(attempt)); + res = (u.password == XXH64(attempt.data(), attempt.size(), 0)); if (res) { u.password = std::hash{}(new_pass); diff --git a/include/user.hpp b/include/user.hpp index b3e3ebe..a54d883 100644 --- a/include/user.hpp +++ b/include/user.hpp @@ -5,14 +5,14 @@ struct User { uint_fast32_t balance = 0; - size_t password; + uint_fast64_t password; /** * @brief User constructor * * @param init_pass initial password */ - User(std::string &&init_pass) : password(std::hash{}(init_pass)) {} + User(std::string &&init_pass) : password(XXH64(init_pass.data(), init_pass.size(), 0)) {} /** * @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(std::hash{}(init_pass)) {} + User(uint_fast32_t init_bal, std::string &&init_pass) : balance(init_bal), password(XXH64(init_pass.data(), init_pass.size(), 0)) {} Json::Value Serialize() const {