mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 08:32:13 +11:00
✨ Hashed Passwords
This commit is contained in:
parent
c1798a83d3
commit
4f4637eec6
3 changed files with 9 additions and 8 deletions
|
|
@ -44,6 +44,7 @@ sudo ./bank <admin password> <saving frequency in minutes> <threads>
|
||||||
- **Tamper Proof** relative to an in-game implementation
|
- **Tamper Proof** relative to an in-game implementation
|
||||||
- **Auto-Saving**, Saves on crash, Saves on close
|
- **Auto-Saving**, Saves on crash, Saves on close
|
||||||
- **HTTPS** (OpenSSL)
|
- **HTTPS** (OpenSSL)
|
||||||
|
- **Passwords are Hashed**, meaning if the bank is compromised passwords wont be leaked
|
||||||
|
|
||||||
### Accessibility
|
### Accessibility
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -53,7 +53,7 @@ public:
|
||||||
bool DelUser(const std::string &name, const std::string &attempt)
|
bool DelUser(const std::string &name, const std::string &attempt)
|
||||||
{
|
{
|
||||||
std::unique_lock<std::shared_mutex> lock{size_lock};
|
std::unique_lock<std::shared_mutex> lock{size_lock};
|
||||||
return users.erase_if(name, [&attempt](const User &u) { return (attempt == u.password); });
|
return users.erase_if(name, [&attempt](const User &u) { return (std::hash<std::string>{}(attempt) == u.password); });
|
||||||
}
|
}
|
||||||
bool AdminDelUser(const std::string &name, const std::string &attempt)
|
bool AdminDelUser(const std::string &name, const std::string &attempt)
|
||||||
{
|
{
|
||||||
|
|
@ -74,7 +74,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 == attempt), state)
|
if (state = (a.balance >= amount) && (a.password == std::hash<std::string>{}(attempt)), state)
|
||||||
{
|
{
|
||||||
a.balance -= amount;
|
a.balance -= amount;
|
||||||
}
|
}
|
||||||
|
|
@ -125,7 +125,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 == attempt;
|
res = u.password == std::hash<std::string>{}(attempt);
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
@ -133,10 +133,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 == attempt);
|
res = (u.password == std::hash<std::string>{}(attempt));
|
||||||
if (res)
|
if (res)
|
||||||
{
|
{
|
||||||
u.password = new_pass;
|
u.password = std::hash<std::string>{}(new_pass);
|
||||||
}
|
}
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
|
|
|
||||||
|
|
@ -5,14 +5,14 @@
|
||||||
struct User
|
struct User
|
||||||
{
|
{
|
||||||
uint_fast32_t balance = 0;
|
uint_fast32_t balance = 0;
|
||||||
std::string password;
|
size_t password;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief User constructor
|
* @brief User constructor
|
||||||
*
|
*
|
||||||
* @param init_pass initial password
|
* @param init_pass initial password
|
||||||
*/
|
*/
|
||||||
User(std::string &&init_pass) : password(init_pass) {}
|
User(std::string &&init_pass) : password(std::hash<std::string>{}(init_pass)) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief User Constructor for admins
|
* @brief User Constructor for admins
|
||||||
|
|
@ -20,7 +20,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) : balance(init_bal), password(init_pass) {}
|
User(uint_fast32_t init_bal, std::string &&init_pass) : balance(init_bal), password(std::hash<std::string>{}(init_pass)) {}
|
||||||
|
|
||||||
Json::Value Serialize() const
|
Json::Value Serialize() const
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Reference in a new issue