mirror of
https://github.com/Expand-sys/CCash
synced 2025-12-17 08:32:13 +11:00
🐛 fixed user/admin filter std::string_view fuckery
This commit is contained in:
parent
27f0c951ad
commit
5275028fd6
5 changed files with 12 additions and 13 deletions
|
|
@ -5,6 +5,4 @@
|
||||||
struct xxHashStringGen
|
struct xxHashStringGen
|
||||||
{
|
{
|
||||||
XXH64_hash_t operator()(const std::string &str) const noexcept;
|
XXH64_hash_t operator()(const std::string &str) const noexcept;
|
||||||
XXH64_hash_t operator()(std::string &&str) const noexcept;
|
|
||||||
XXH64_hash_t operator()(std::string_view str) const noexcept;
|
|
||||||
};
|
};
|
||||||
|
|
|
||||||
|
|
@ -20,9 +20,11 @@ void AdminFilter::doFilter(const HttpRequestPtr &req,
|
||||||
std::size_t middle = results_view.find(':');
|
std::size_t middle = results_view.find(':');
|
||||||
if (middle != std::string::npos)
|
if (middle != std::string::npos)
|
||||||
{
|
{
|
||||||
|
base64_result[middle] = '\0';
|
||||||
std::string_view username = results_view.substr(0, middle);
|
std::string_view username = results_view.substr(0, middle);
|
||||||
if (bank.AdminVerifyAccount(username))
|
if (bank.AdminVerifyAccount(username))
|
||||||
{
|
{
|
||||||
|
base64_result[new_sz] = '\0';
|
||||||
std::string_view password = results_view.substr(middle + 1);
|
std::string_view password = results_view.substr(middle + 1);
|
||||||
if (bank.VerifyPassword(username, password))
|
if (bank.VerifyPassword(username, password))
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -129,7 +129,7 @@ BankResponse Bank::SendFunds(const std::string &a_name, const std::string &b_nam
|
||||||
bool Bank::VerifyPassword(std::string_view name, std::string_view attempt) const noexcept
|
bool Bank::VerifyPassword(std::string_view name, std::string_view attempt) const noexcept
|
||||||
{
|
{
|
||||||
bool res = false;
|
bool res = false;
|
||||||
users.if_contains(name.data(), [&res, &attempt](const User &u) { res = (u.password == xxHashStringGen{}(attempt)); });
|
users.if_contains(name.data(), [&res, &attempt](const User &u) { res = (u.password == xxHashStringGen{}(attempt.data())); });
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
@ -217,6 +217,8 @@ bool Bank::AdminVerifyAccount(std::string_view name) noexcept
|
||||||
|
|
||||||
BankResponse Bank::AddUser(std::string &&name, uint32_t init_bal, std::string &&init_pass) noexcept
|
BankResponse Bank::AddUser(std::string &&name, uint32_t init_bal, std::string &&init_pass) noexcept
|
||||||
{
|
{
|
||||||
|
std::cout << name << '\n'
|
||||||
|
<< init_pass << '\n';
|
||||||
if (!ValidUsrname(name))
|
if (!ValidUsrname(name))
|
||||||
{
|
{
|
||||||
return {k400BadRequest, "Invalid Name, breaks size and/or character restrictions"};
|
return {k400BadRequest, "Invalid Name, breaks size and/or character restrictions"};
|
||||||
|
|
@ -284,7 +286,7 @@ void Bank::Save()
|
||||||
for (const auto &u : users)
|
for (const auto &u : users)
|
||||||
{
|
{
|
||||||
//we know it contains this key but we call this func to grab mutex
|
//we know it contains this key but we call this func to grab mutex
|
||||||
users.if_contains(u.first, [&temp, &u](const User &u_val) { temp[u.first.data()] = u_val.Serialize(); });
|
users.if_contains(u.first, [&temp, &u](const User &u_val) { temp[u.first] = u_val.Serialize(); });
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if (temp.isNull())
|
if (temp.isNull())
|
||||||
|
|
|
||||||
|
|
@ -20,8 +20,12 @@ void UserFilter::doFilter(const HttpRequestPtr &req,
|
||||||
std::size_t middle = results_view.find(':');
|
std::size_t middle = results_view.find(':');
|
||||||
if (middle != std::string::npos)
|
if (middle != std::string::npos)
|
||||||
{
|
{
|
||||||
|
base64_result[middle] = '\0';
|
||||||
|
base64_result[new_sz] = '\0';
|
||||||
|
|
||||||
std::string_view username = results_view.substr(0, middle);
|
std::string_view username = results_view.substr(0, middle);
|
||||||
std::string_view password = results_view.substr(middle + 1);
|
std::string_view password = results_view.substr(middle + 1);
|
||||||
|
|
||||||
if (bank.VerifyPassword(username, password))
|
if (bank.VerifyPassword(username, password))
|
||||||
{
|
{
|
||||||
fccb();
|
fccb();
|
||||||
|
|
|
||||||
|
|
@ -1,14 +1,7 @@
|
||||||
#include "xxhash_str.h"
|
#include "xxhash_str.h"
|
||||||
|
#include <iostream>
|
||||||
|
|
||||||
XXH64_hash_t xxHashStringGen::operator()(const std::string &str) const noexcept
|
XXH64_hash_t xxHashStringGen::operator()(const std::string &str) const noexcept
|
||||||
{
|
{
|
||||||
return XXH3_64bits(str.data(), str.size());
|
return XXH3_64bits(str.data(), str.size());
|
||||||
}
|
}
|
||||||
XXH64_hash_t xxHashStringGen::operator()(std::string &&str) const noexcept
|
|
||||||
{
|
|
||||||
return XXH3_64bits(str.data(), str.size());
|
|
||||||
}
|
|
||||||
XXH64_hash_t xxHashStringGen::operator()(std::string_view str) const noexcept
|
|
||||||
{
|
|
||||||
return XXH3_64bits(str.data(), str.size());
|
|
||||||
}
|
|
||||||
Loading…
Reference in a new issue