mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 00:22:14 +11:00
🐛 std::hash was deterministic
This commit is contained in:
parent
aead847df9
commit
8cb4702825
2 changed files with 8 additions and 7 deletions
|
|
@ -2,6 +2,7 @@
|
|||
#include <fstream>
|
||||
#include <shared_mutex>
|
||||
#include <vector>
|
||||
#include <xxh3.h>
|
||||
#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<std::shared_mutex> lock{size_lock};
|
||||
return users.erase_if(name, [&attempt](const User &u) { return (std::hash<std::string>{}(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<std::shared_mutex> 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<std::string>{}(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<std::string>{}(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<std::string>{}(attempt));
|
||||
res = (u.password == XXH64(attempt.data(), attempt.size(), 0));
|
||||
if (res)
|
||||
{
|
||||
u.password = std::hash<std::string>{}(new_pass);
|
||||
|
|
|
|||
|
|
@ -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<std::string>{}(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<std::string>{}(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
|
||||
{
|
||||
|
|
|
|||
Loading…
Reference in a new issue