mirror of
https://github.com/TrinityCore/TrinityCore.git
synced 2026-01-20 01:15:35 +01:00
Core/Accounts: Migrate RA credentials checking to use AccountMgr instead of copying its logic
(cherry picked from commit e05541665b)
This commit is contained in:
@@ -344,6 +344,25 @@ bool AccountMgr::GetEmail(uint32 accountId, std::string& email)
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AccountMgr::CheckPassword(std::string username, std::string password)
|
||||
{
|
||||
Utf8ToUpperOnlyLatin(username);
|
||||
Utf8ToUpperOnlyLatin(password);
|
||||
|
||||
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_CHECK_PASSWORD_BY_NAME);
|
||||
stmt->setString(0, username);
|
||||
|
||||
if (PreparedQueryResult result = LoginDatabase.Query(stmt))
|
||||
{
|
||||
Trinity::Crypto::SRP6::Salt salt = (*result)[0].GetBinary<Trinity::Crypto::SRP6::SALT_LENGTH>();
|
||||
Trinity::Crypto::SRP6::Verifier verifier = (*result)[1].GetBinary<Trinity::Crypto::SRP6::VERIFIER_LENGTH>();
|
||||
if (Trinity::Crypto::SRP6::CheckLogin(username, password, salt, verifier))
|
||||
return true;
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
bool AccountMgr::CheckPassword(uint32 accountId, std::string password)
|
||||
{
|
||||
std::string username;
|
||||
|
||||
@@ -64,6 +64,7 @@ class TC_GAME_API AccountMgr
|
||||
static AccountOpResult ChangePassword(uint32 accountId, std::string newPassword);
|
||||
static AccountOpResult ChangeEmail(uint32 accountId, std::string newEmail);
|
||||
static AccountOpResult ChangeRegEmail(uint32 accountId, std::string newEmail);
|
||||
static bool CheckPassword(std::string username, std::string password);
|
||||
static bool CheckPassword(uint32 accountId, std::string password);
|
||||
static bool CheckEmail(uint32 accountId, std::string newEmail);
|
||||
|
||||
|
||||
@@ -20,7 +20,6 @@
|
||||
#include "Config.h"
|
||||
#include "DatabaseEnv.h"
|
||||
#include "Log.h"
|
||||
#include "SRP6.h"
|
||||
#include "Util.h"
|
||||
#include "World.h"
|
||||
#include <boost/asio/buffer.hpp>
|
||||
@@ -62,7 +61,7 @@ void RASession::Start()
|
||||
if (password.empty())
|
||||
return;
|
||||
|
||||
if (!CheckAccessLevel(username) || !CheckPassword(username, password))
|
||||
if (!CheckAccessLevel(username) || !AccountMgr::CheckPassword(username, password))
|
||||
{
|
||||
Send("Authentication failed\r\n");
|
||||
_socket.close();
|
||||
@@ -150,31 +149,6 @@ bool RASession::CheckAccessLevel(const std::string& user)
|
||||
return true;
|
||||
}
|
||||
|
||||
bool RASession::CheckPassword(const std::string& user, const std::string& pass)
|
||||
{
|
||||
std::string safe_user = user;
|
||||
Utf8ToUpperOnlyLatin(safe_user);
|
||||
|
||||
std::string safe_pass = pass;
|
||||
Utf8ToUpperOnlyLatin(safe_pass);
|
||||
|
||||
LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_SEL_CHECK_PASSWORD_BY_NAME);
|
||||
|
||||
stmt->setString(0, safe_user);
|
||||
|
||||
if (PreparedQueryResult result = LoginDatabase.Query(stmt))
|
||||
{
|
||||
Trinity::Crypto::SRP6::Salt salt = (*result)[0].GetBinary<Trinity::Crypto::SRP6::SALT_LENGTH>();
|
||||
Trinity::Crypto::SRP6::Verifier verifier = (*result)[1].GetBinary<Trinity::Crypto::SRP6::VERIFIER_LENGTH>();
|
||||
|
||||
if (Trinity::Crypto::SRP6::CheckLogin(safe_user, safe_pass, salt, verifier))
|
||||
return true;
|
||||
}
|
||||
|
||||
TC_LOG_INFO("commands.ra", "Wrong password for user: {}", user);
|
||||
return false;
|
||||
}
|
||||
|
||||
bool RASession::ProcessCommand(std::string& command)
|
||||
{
|
||||
if (command.length() == 0)
|
||||
|
||||
@@ -42,7 +42,6 @@ private:
|
||||
int Send(std::string_view data);
|
||||
std::string ReadString();
|
||||
bool CheckAccessLevel(const std::string& user);
|
||||
bool CheckPassword(const std::string& user, const std::string& pass);
|
||||
bool ProcessCommand(std::string& command);
|
||||
|
||||
static void CommandPrint(void* callbackArg, std::string_view text);
|
||||
|
||||
Reference in New Issue
Block a user