🐎 replaced hash function

This commit is contained in:
EntireTwix 2021-04-19 06:58:56 -07:00
parent bf91a2ab50
commit 17091ad9d2
4 changed files with 10 additions and 9 deletions

View file

@ -33,7 +33,7 @@ make -j<threads>
sudo ./bank <admin password> <saving frequency in minutes> <threads> sudo ./bank <admin password> <saving frequency in minutes> <threads>
``` ```
you also have to edit the config file to add your cert locations, I personally use cert bot **you also have to edit the config file to add your cert locations**, I personally use cert bot
### Connected Services ### Connected Services
@ -77,6 +77,7 @@ Ideas:
- **Web front-end** - **Web front-end**
- **RESTful** API for connected services like a market, gambling, or anything else you can think of - **RESTful** API for connected services like a market, gambling, or anything else you can think of
- able to be used millions of blocks away, across dimensions, servers, **vanilla or modded**. In contrast to an in-game modded implementation that would be range limited. - able to be used millions of blocks away, across dimensions, servers, **vanilla or modded**. In contrast to an in-game modded implementation that would be range limited.
- **Logging**
#### Dependencies #### Dependencies

View file

@ -54,7 +54,7 @@ public:
bool DelUser(const std::string &name, const std::string &attempt) bool DelUser(const std::string &name, const std::string &attempt)
{ {
std::shared_lock<std::shared_mutex> lock{size_lock}; std::shared_lock<std::shared_mutex> lock{size_lock};
return users.erase_if(name, [&attempt](const User &u) { return (XXH64(attempt.data(), attempt.size(), 1) == u.password); }); return users.erase_if(name, [&attempt](const User &u) { return (XXH3_64bits(attempt.data(), attempt.size()) == u.password); });
} }
bool AdminDelUser(const std::string &name, const std::string &attempt) bool AdminDelUser(const std::string &name, const std::string &attempt)
{ {
@ -75,7 +75,7 @@ public:
bool state = false; bool state = false;
std::shared_lock<std::shared_mutex> lock{send_funds_l}; //because SendFunds requires 3 locking operations 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) { users.modify_if(a_name, [&state, amount, &attempt](User &a) {
if (state = (a.balance >= amount) && (a.password == XXH64(attempt.data(), attempt.size(), 1))) if (state = (a.balance >= amount) && (a.password == XXH3_64bits(attempt.data(), attempt.size())))
{ {
a.balance -= amount; a.balance -= amount;
} }
@ -130,7 +130,7 @@ public:
{ {
int_fast8_t res = -1; int_fast8_t res = -1;
users.if_contains(name, [&res, &attempt](const User &u) { users.if_contains(name, [&res, &attempt](const User &u) {
res = u.password == XXH64(attempt.data(), attempt.size(), 1); res = u.password == XXH3_64bits(attempt.data(), attempt.size());
}); });
return res; return res;
} }
@ -138,10 +138,10 @@ public:
{ {
int_fast8_t res = -1; int_fast8_t res = -1;
users.modify_if(name, [&res, &attempt, &new_pass](User &u) { users.modify_if(name, [&res, &attempt, &new_pass](User &u) {
res = (u.password == XXH64(attempt.data(), attempt.size(), 1)); res = (u.password == XXH3_64bits(attempt.data(), attempt.size()));
if (res) if (res)
{ {
u.password = XXH64(new_pass.data(), new_pass.size(), 1); u.password = XXH3_64bits(new_pass.data(), new_pass.size());
} }
}); });
return res; return res;

View file

@ -13,7 +13,7 @@ struct User
* *
* @param init_pass initial password * @param init_pass initial password
*/ */
User(std::string &&init_pass) : password(XXH64(init_pass.data(), init_pass.size(), 1)) {} User(std::string &&init_pass) : password(XXH3_64bits(init_pass.data(), init_pass.size())) {}
/** /**
* @brief User Constructor for admins * @brief User Constructor for admins
@ -21,7 +21,7 @@ struct User
* @param init_bal initial balance * @param init_bal initial balance
* @param init_pass initial password * @param init_pass initial password
*/ */
User(uint_fast32_t init_bal, std::string &&init_pass, bool state = false) : balance(init_bal), password(XXH64(init_pass.data(), init_pass.size(), 1)), is_admin(state) {} User(uint_fast32_t init_bal, std::string &&init_pass, bool state = false) : balance(init_bal), password(XXH3_64bits(init_pass.data(), init_pass.size())), is_admin(state) {}
User(uint_fast32_t init_bal, uint64_t init_pass, bool state = false) : balance(init_bal), password(init_pass), is_admin(state) {} User(uint_fast32_t init_bal, uint64_t init_pass, bool state = false) : balance(init_bal), password(init_pass), is_admin(state) {}
Json::Value Serialize() const Json::Value Serialize() const

View file

@ -44,7 +44,7 @@ int main(int argc, char **argv)
[](const drogon::HttpRequestPtr &req, const drogon::HttpResponsePtr &resp) { [](const drogon::HttpRequestPtr &req, const drogon::HttpResponsePtr &resp) {
resp->addHeader("Access-Control-Allow-Origin", "*"); resp->addHeader("Access-Control-Allow-Origin", "*");
}); });
app().loadConfigFile("../config.json").addListener("0.0.0.0", 80).registerController(API).setThreadNum(std::stoul(argv[3])).enableRunAsDaemon().run(); app().loadConfigFile("../config.json").registerController(API).setThreadNum(std::stoul(argv[3])).enableRunAsDaemon().run();
return 0; return 0;
} }