mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 00:22:14 +11:00
🚚 moved hash function to seperate header
This commit is contained in:
parent
00a3d0c075
commit
d93786f4ff
6 changed files with 19 additions and 14 deletions
|
|
@ -14,14 +14,6 @@ using BankResponse = std::pair<drogon::HttpStatusCode, Json::Value>;
|
||||||
|
|
||||||
class Bank
|
class Bank
|
||||||
{
|
{
|
||||||
struct xxHashStringGen
|
|
||||||
{
|
|
||||||
inline uint64_t operator()(const std::string &str) const
|
|
||||||
{
|
|
||||||
return XXH3_64bits(str.data(), str.size());
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
phmap::parallel_flat_hash_map<
|
phmap::parallel_flat_hash_map<
|
||||||
std::string, User,
|
std::string, User,
|
||||||
xxHashStringGen,
|
xxHashStringGen,
|
||||||
|
|
|
||||||
|
|
@ -1,7 +1,6 @@
|
||||||
#pragma once
|
#pragma once
|
||||||
#include <json/json.h> //to be removed later
|
#include <json/json.h> //to be removed later
|
||||||
#include <string>
|
#include "xxhash_str.h"
|
||||||
#include <xxhash.h>
|
|
||||||
#include "log.h"
|
#include "log.h"
|
||||||
|
|
||||||
struct User
|
struct User
|
||||||
|
|
|
||||||
8
include/xxhash_str.h
Normal file
8
include/xxhash_str.h
Normal file
|
|
@ -0,0 +1,8 @@
|
||||||
|
#pragma once
|
||||||
|
#include <string>
|
||||||
|
#include <xxhash.h>
|
||||||
|
|
||||||
|
struct xxHashStringGen
|
||||||
|
{
|
||||||
|
uint64_t operator()(const std::string &str) const noexcept;
|
||||||
|
};
|
||||||
|
|
@ -106,7 +106,7 @@ bool Bank::VerifyPassword(const std::string &name, const std::string &attempt) c
|
||||||
{
|
{
|
||||||
bool res = false;
|
bool res = false;
|
||||||
users.if_contains(name, [&res, &attempt](const User &u) {
|
users.if_contains(name, [&res, &attempt](const User &u) {
|
||||||
res = (u.password == XXH3_64bits(attempt.data(), attempt.size()));
|
res = (u.password == xxHashStringGen{}(attempt));
|
||||||
});
|
});
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
@ -114,7 +114,7 @@ bool Bank::VerifyPassword(const std::string &name, const std::string &attempt) c
|
||||||
void Bank::ChangePassword(const std::string &name, std::string &&new_pass) noexcept
|
void Bank::ChangePassword(const std::string &name, std::string &&new_pass) noexcept
|
||||||
{
|
{
|
||||||
users.modify_if(name, [&new_pass](User &u) {
|
users.modify_if(name, [&new_pass](User &u) {
|
||||||
u.password = XXH3_64bits(new_pass.data(), new_pass.size());
|
u.password = xxHashStringGen{}(new_pass);
|
||||||
});
|
});
|
||||||
#if CONSERVATIVE_DISK_SAVE
|
#if CONSERVATIVE_DISK_SAVE
|
||||||
save_flag.SetChangesOn();
|
save_flag.SetChangesOn();
|
||||||
|
|
|
||||||
|
|
@ -5,7 +5,7 @@
|
||||||
*
|
*
|
||||||
* @param init_pass initial password
|
* @param init_pass initial password
|
||||||
*/
|
*/
|
||||||
User::User(std::string &&init_pass) noexcept : password(XXH3_64bits(init_pass.data(), init_pass.size())) {}
|
User::User(std::string &&init_pass) noexcept : password(xxHashStringGen{}(init_pass)) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief User Constructor for admins
|
* @brief User Constructor for admins
|
||||||
|
|
@ -13,7 +13,7 @@ User::User(std::string &&init_pass) noexcept : password(XXH3_64bits(init_pass.da
|
||||||
* @param init_bal initial balance
|
* @param init_bal initial balance
|
||||||
* @param init_pass initial password
|
* @param init_pass initial password
|
||||||
*/
|
*/
|
||||||
User::User(uint32_t init_bal, std::string &&init_pass) noexcept : balance(init_bal), password(XXH3_64bits(init_pass.data(), init_pass.size())) {}
|
User::User(uint32_t init_bal, std::string &&init_pass) noexcept : balance(init_bal), password(xxHashStringGen{}(init_pass)) {}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @brief User Constructor for loading
|
* @brief User Constructor for loading
|
||||||
|
|
|
||||||
6
src/xxhash_str.cpp
Normal file
6
src/xxhash_str.cpp
Normal file
|
|
@ -0,0 +1,6 @@
|
||||||
|
#include "xxhash_str.h"
|
||||||
|
|
||||||
|
uint64_t xxHashStringGen::operator()(const std::string &str) const noexcept
|
||||||
|
{
|
||||||
|
return XXH3_64bits(str.data(), str.size());
|
||||||
|
}
|
||||||
Loading…
Reference in a new issue