diff options
author | Shauren <shauren.trinity@gmail.com> | 2023-12-26 14:55:15 +0100 |
---|---|---|
committer | Shauren <shauren.trinity@gmail.com> | 2023-12-26 14:55:15 +0100 |
commit | 623202d68e862b346b22ac65f9dcbb498d2fa2ac (patch) | |
tree | fd882ea858e1668d2f79c1232ea5c0bf50001488 /src/server/game/Accounts/AccountMgr.cpp | |
parent | 4a61675191c91c7d09def0e612f2e11a646845b0 (diff) |
Core/Bnet: Implemented new SRP6 variants, and migrate old sha_pass_hash in battlenet_accounts to separate salt and verifier columns
* passwords can now be case sensitive and up to 128 characters long
Diffstat (limited to 'src/server/game/Accounts/AccountMgr.cpp')
-rw-r--r-- | src/server/game/Accounts/AccountMgr.cpp | 32 |
1 files changed, 17 insertions, 15 deletions
diff --git a/src/server/game/Accounts/AccountMgr.cpp b/src/server/game/Accounts/AccountMgr.cpp index 0229dd686b4..113e81153ba 100644 --- a/src/server/game/Accounts/AccountMgr.cpp +++ b/src/server/game/Accounts/AccountMgr.cpp @@ -29,6 +29,8 @@ #include "World.h" #include "WorldSession.h" +using AccountSRP6 = Trinity::Crypto::SRP::GruntSRP6; + AccountMgr::AccountMgr() { } AccountMgr::~AccountMgr() @@ -60,9 +62,9 @@ AccountOpResult AccountMgr::CreateAccount(std::string username, std::string pass LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT); stmt->setString(0, username); - std::pair<Trinity::Crypto::SRP6::Salt, Trinity::Crypto::SRP6::Verifier> registrationData = Trinity::Crypto::SRP6::MakeRegistrationData(username, password); - stmt->setBinary(1, registrationData.first); - stmt->setBinary(2, registrationData.second); + auto [salt, verifier] = Trinity::Crypto::SRP6::MakeRegistrationData<AccountSRP6>(username, password); + stmt->setBinary(1, salt); + stmt->setBinary(2, verifier); stmt->setString(3, email); stmt->setString(4, email); @@ -184,10 +186,10 @@ AccountOpResult AccountMgr::ChangeUsername(uint32 accountId, std::string newUser stmt->setUInt32(1, accountId); LoginDatabase.Execute(stmt); - std::pair<Trinity::Crypto::SRP6::Salt, Trinity::Crypto::SRP6::Verifier> registrationData = Trinity::Crypto::SRP6::MakeRegistrationData(newUsername, newPassword); + auto [salt, verifier] = Trinity::Crypto::SRP6::MakeRegistrationData<AccountSRP6>(newUsername, newPassword); stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_LOGON); - stmt->setBinary(0, registrationData.first); - stmt->setBinary(1, registrationData.second); + stmt->setBinary(0, salt); + stmt->setBinary(1, verifier); stmt->setUInt32(2, accountId); LoginDatabase.Execute(stmt); @@ -212,11 +214,11 @@ AccountOpResult AccountMgr::ChangePassword(uint32 accountId, std::string newPass Utf8ToUpperOnlyLatin(username); Utf8ToUpperOnlyLatin(newPassword); - std::pair<Trinity::Crypto::SRP6::Salt, Trinity::Crypto::SRP6::Verifier> registrationData = Trinity::Crypto::SRP6::MakeRegistrationData(username, newPassword); + auto [salt, verifier] = Trinity::Crypto::SRP6::MakeRegistrationData<AccountSRP6>(username, newPassword); LoginDatabasePreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_LOGON); - stmt->setBinary(0, registrationData.first); - stmt->setBinary(1, registrationData.second); + stmt->setBinary(0, salt); + stmt->setBinary(1, verifier); stmt->setUInt32(2, accountId); LoginDatabase.Execute(stmt); @@ -354,9 +356,9 @@ bool AccountMgr::CheckPassword(std::string username, std::string password) 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)) + Trinity::Crypto::SRP::Salt salt = (*result)[0].GetBinary<Trinity::Crypto::SRP::SALT_LENGTH>(); + Trinity::Crypto::SRP::Verifier verifier = (*result)[1].GetBinary(); + if (AccountSRP6(username, salt, verifier).CheckCredentials(username, password)) return true; } @@ -378,9 +380,9 @@ bool AccountMgr::CheckPassword(uint32 accountId, std::string password) 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)) + Trinity::Crypto::SRP::Salt salt = (*result)[0].GetBinary<Trinity::Crypto::SRP::SALT_LENGTH>(); + Trinity::Crypto::SRP::Verifier verifier = (*result)[1].GetBinary(); + if (AccountSRP6(username, salt, verifier).CheckCredentials(username, password)) return true; } |