mirror of
https://github.com/KartKrewDev/RingRacers.git
synced 2025-10-30 08:01:28 +00:00
Add M_TryExactPassword
Single-use password technology that exists outside of the enumerated list
This commit is contained in:
parent
6c0118d491
commit
54d6914b50
2 changed files with 24 additions and 10 deletions
33
src/m_pw.cpp
33
src/m_pw.cpp
|
|
@ -43,22 +43,21 @@ namespace
|
||||||
|
|
||||||
constexpr const UINT8 kRRSalt[17] = "0L4rlK}{9ay6'VJS";
|
constexpr const UINT8 kRRSalt[17] = "0L4rlK}{9ay6'VJS";
|
||||||
|
|
||||||
|
std::array<UINT8, M_PW_BUF_SIZE> decode_hash(std::string encoded)
|
||||||
|
{
|
||||||
|
std::array<UINT8, M_PW_BUF_SIZE> decoded;
|
||||||
|
if (modp::b64_decode(encoded).size() != decoded.size())
|
||||||
|
throw std::invalid_argument("hash is incorrectly sized");
|
||||||
|
std::copy(encoded.begin(), encoded.end(), decoded.begin());
|
||||||
|
return decoded;
|
||||||
|
}
|
||||||
|
|
||||||
struct Pw
|
struct Pw
|
||||||
{
|
{
|
||||||
Pw(void (*cb)(), const char *encoded_hash) : cb_(cb), hash_(decode_hash(encoded_hash)) {}
|
Pw(void (*cb)(), const char *encoded_hash) : cb_(cb), hash_(decode_hash(encoded_hash)) {}
|
||||||
|
|
||||||
void (*cb_)();
|
void (*cb_)();
|
||||||
const std::array<UINT8, M_PW_BUF_SIZE> hash_;
|
const std::array<UINT8, M_PW_BUF_SIZE> hash_;
|
||||||
|
|
||||||
private:
|
|
||||||
static std::array<UINT8, M_PW_BUF_SIZE> decode_hash(std::string encoded)
|
|
||||||
{
|
|
||||||
std::array<UINT8, M_PW_BUF_SIZE> decoded;
|
|
||||||
if (modp::b64_decode(encoded).size() != decoded.size())
|
|
||||||
throw std::invalid_argument("hash is incorrectly sized");
|
|
||||||
std::copy(encoded.begin(), encoded.end(), decoded.begin());
|
|
||||||
return decoded;
|
|
||||||
}
|
|
||||||
};
|
};
|
||||||
|
|
||||||
std::vector<Pw> passwords;
|
std::vector<Pw> passwords;
|
||||||
|
|
@ -342,6 +341,20 @@ try_password_e M_TryPassword(const char *password, boolean conditions)
|
||||||
return return_code;
|
return return_code;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
boolean M_TryExactPassword(const char *password, const char *encodedhash)
|
||||||
|
{
|
||||||
|
// Normalize input casing
|
||||||
|
std::string key = password;
|
||||||
|
strlwr(key.data());
|
||||||
|
|
||||||
|
UINT8 key_hash[M_PW_HASH_SIZE];
|
||||||
|
M_HashPassword(key_hash, key.c_str(), kRRSalt);
|
||||||
|
|
||||||
|
auto hash = decode_hash(encodedhash);
|
||||||
|
|
||||||
|
return (memcmp(key_hash, hash.data(), M_PW_HASH_SIZE) == 0);
|
||||||
|
}
|
||||||
|
|
||||||
#ifdef DEVELOP
|
#ifdef DEVELOP
|
||||||
void Command_Crypt_f(void)
|
void Command_Crypt_f(void)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -27,6 +27,7 @@ try_password_e;
|
||||||
|
|
||||||
void M_PasswordInit(void);
|
void M_PasswordInit(void);
|
||||||
try_password_e M_TryPassword(const char *password, boolean challenges);
|
try_password_e M_TryPassword(const char *password, boolean challenges);
|
||||||
|
boolean M_TryExactPassword(const char *password, const char *encodedhash);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
} // extern "C"
|
} // extern "C"
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue