TrinityCore
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
Battlenet::AccountMgr Namespace Reference

Functions

TC_GAME_API AccountOpResult CreateBattlenetAccount (std::string email, std::string password, bool withGameAccount=true)
 
TC_GAME_API AccountOpResult ChangePassword (uint32 accountId, std::string newPassword)
 
TC_GAME_API bool CheckPassword (uint32 accountId, std::string password)
 
TC_GAME_API AccountOpResult LinkWithGameAccount (std::string const &email, std::string const &gameAccountName)
 
TC_GAME_API AccountOpResult UnlinkGameAccount (std::string const &gameAccountName)
 
TC_GAME_API uint32 GetId (std::string const &username)
 
TC_GAME_API bool GetName (uint32 accountId, std::string &name)
 
TC_GAME_API uint32 GetIdByGameAccount (uint32 gameAccountId)
 
TC_GAME_API uint8 GetMaxIndex (uint32 accountId)
 
TC_GAME_API std::string CalculateShaPassHash (std::string const &name, std::string const &password)
 

Function Documentation

std::string Battlenet::AccountMgr::CalculateShaPassHash ( std::string const name,
std::string const password 
)
173 {
174  SHA256Hash email;
175  email.UpdateData(name);
176  email.Finalize();
177 
178  SHA256Hash sha;
179  sha.UpdateData(ByteArrayToHexStr(email.GetDigest(), email.GetLength()));
180  sha.UpdateData(":");
181  sha.UpdateData(password);
182  sha.Finalize();
183 
184  return ByteArrayToHexStr(sha.GetDigest(), sha.GetLength(), true);
185 }
Definition: SHA256.h:28
uint8 * GetDigest(void)
Definition: SHA256.h:44
void UpdateData(const uint8 *dta, int len)
Definition: SHA256.cpp:34
std::string ByteArrayToHexStr(uint8 const *bytes, uint32 arrayLen, bool reverse)
Definition: Util.cpp:509
void Finalize()
Definition: SHA256.cpp:64
int GetLength(void) const
Definition: SHA256.h:45

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

AccountOpResult Battlenet::AccountMgr::ChangePassword ( uint32  accountId,
std::string  newPassword 
)
55 {
56  std::string username;
57  if (!GetName(accountId, username))
58  return AccountOpResult::AOR_NAME_NOT_EXIST; // account doesn't exist
59 
60  Utf8ToUpperOnlyLatin(username);
61  Utf8ToUpperOnlyLatin(newPassword);
62  if (utf8length(newPassword) > MAX_PASS_STR)
64 
66  stmt->setString(0, CalculateShaPassHash(username, newPassword));
67  stmt->setUInt32(1, accountId);
68  LoginDatabase.Execute(stmt);
69 
71 }
TC_GAME_API std::string CalculateShaPassHash(std::string const &name, std::string const &password)
Definition: BattlenetAccountMgr.cpp:172
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
void setString(const uint8 index, const std::string &value)
Definition: PreparedStatement.cpp:187
size_t utf8length(std::string &utf8str)
Definition: Util.cpp:247
Definition: PreparedStatement.h:74
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
TC_GAME_API bool GetName(uint32 accountId, std::string &name)
Definition: BattlenetAccountMgr.cpp:138
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
Definition: LoginDatabase.h:124
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:498
#define MAX_PASS_STR
Definition: AccountMgr.h:43

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Battlenet::AccountMgr::CheckPassword ( uint32  accountId,
std::string  password 
)
74 {
75  std::string username;
76 
77  if (!GetName(accountId, username))
78  return false;
79 
80  Utf8ToUpperOnlyLatin(username);
81  Utf8ToUpperOnlyLatin(password);
82 
84  stmt->setUInt32(0, accountId);
85  stmt->setString(1, CalculateShaPassHash(username, password));
86 
87  return LoginDatabase.Query(stmt) != nullptr;
88 }
TC_GAME_API std::string CalculateShaPassHash(std::string const &name, std::string const &password)
Definition: BattlenetAccountMgr.cpp:172
void setString(const uint8 index, const std::string &value)
Definition: PreparedStatement.cpp:187
Definition: PreparedStatement.h:74
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
TC_GAME_API bool GetName(uint32 accountId, std::string &name)
Definition: BattlenetAccountMgr.cpp:138
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
Definition: LoginDatabase.h:125
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:498

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

AccountOpResult Battlenet::AccountMgr::CreateBattlenetAccount ( std::string  email,
std::string  password,
bool  withGameAccount = true 
)
27 {
28  if (utf8length(email) > MAX_BNET_EMAIL_STR)
30 
31  if (utf8length(password) > MAX_PASS_STR)
33 
34  Utf8ToUpperOnlyLatin(email);
35  Utf8ToUpperOnlyLatin(password);
36 
37  if (GetId(email))
39 
41  stmt->setString(0, email);
42  stmt->setString(1, CalculateShaPassHash(email, password));
44 
45  uint32 newAccountId = GetId(email);
46  ASSERT(newAccountId);
47 
48  if (withGameAccount)
49  GameAccountMgr::instance()->CreateAccount(std::to_string(newAccountId) + "#1", password, email, newAccountId, 1);
50 
52 }
TC_GAME_API std::string CalculateShaPassHash(std::string const &name, std::string const &password)
Definition: BattlenetAccountMgr.cpp:172
static AccountMgr * instance()
Definition: AccountMgr.cpp:36
void setString(const uint8 index, const std::string &value)
Definition: PreparedStatement.cpp:187
size_t utf8length(std::string &utf8str)
Definition: Util.cpp:247
Definition: LoginDatabase.h:121
#define MAX_BNET_EMAIL_STR
Definition: BattlenetAccountMgr.h:26
Definition: PreparedStatement.h:74
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
TC_GAME_API uint32 GetId(std::string const &username)
Definition: BattlenetAccountMgr.cpp:128
uint32_t uint32
Definition: Define.h:150
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
#define ASSERT
Definition: Errors.h:55
bool Utf8ToUpperOnlyLatin(std::string &utf8String)
Definition: Util.cpp:498
#define MAX_PASS_STR
Definition: AccountMgr.h:43
void DirectExecute(const char *sql)
Definition: DatabaseWorkerPool.h:121
AccountOpResult CreateAccount(std::string username, std::string password, std::string email="", uint32 bnetAccountId=0, uint8 bnetIndex=0)
Definition: AccountMgr.cpp:42

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32 Battlenet::AccountMgr::GetId ( std::string const username)
129 {
131  stmt->setString(0, username);
132  if (PreparedQueryResult result = LoginDatabase.Query(stmt))
133  return (*result)[0].GetUInt32();
134 
135  return 0;
136 }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
void setString(const uint8 index, const std::string &value)
Definition: PreparedStatement.cpp:187
Definition: PreparedStatement.h:74
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
Definition: LoginDatabase.h:123
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint32 Battlenet::AccountMgr::GetIdByGameAccount ( uint32  gameAccountId)
152 {
154  stmt->setUInt32(0, gameAccountId);
155  if (PreparedQueryResult result = LoginDatabase.Query(stmt))
156  return (*result)[0].GetUInt32();
157 
158  return 0;
159 }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Definition: PreparedStatement.h:74
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
Definition: LoginDatabase.h:128
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

uint8 Battlenet::AccountMgr::GetMaxIndex ( uint32  accountId)
162 {
164  stmt->setUInt32(0, accountId);
165  PreparedQueryResult result = LoginDatabase.Query(stmt);
166  if (result)
167  return (*result)[0].GetUInt8();
168 
169  return 0;
170 }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Definition: PreparedStatement.h:74
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
Definition: LoginDatabase.h:130
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

bool Battlenet::AccountMgr::GetName ( uint32  accountId,
std::string &  name 
)
139 {
141  stmt->setUInt32(0, accountId);
142  if (PreparedQueryResult result = LoginDatabase.Query(stmt))
143  {
144  name = (*result)[0].GetString();
145  return true;
146  }
147 
148  return false;
149 }
std::shared_ptr< PreparedResultSet > PreparedQueryResult
Definition: QueryResult.h:107
Definition: PreparedStatement.h:74
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
QueryResult Query(const char *sql, T *connection=nullptr)
Definition: DatabaseWorkerPool.cpp:113
Definition: LoginDatabase.h:122

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

AccountOpResult Battlenet::AccountMgr::LinkWithGameAccount ( std::string const email,
std::string const gameAccountName 
)
91 {
92  uint32 bnetAccountId = GetId(email);
93  if (!bnetAccountId)
95 
96  uint32 gameAccountId = GameAccountMgr::GetId(gameAccountName);
97  if (!gameAccountId)
99 
100  if (GetIdByGameAccount(gameAccountId))
102 
104  stmt->setUInt32(0, bnetAccountId);
105  stmt->setUInt8(1, GetMaxIndex(bnetAccountId) + 1);
106  stmt->setUInt32(2, gameAccountId);
107  LoginDatabase.Execute(stmt);
109 }
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
void setUInt8(const uint8 index, const uint8 value)
Definition: PreparedStatement.cpp:97
Definition: PreparedStatement.h:74
TC_GAME_API uint8 GetMaxIndex(uint32 accountId)
Definition: BattlenetAccountMgr.cpp:161
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
TC_GAME_API uint32 GetId(std::string const &username)
Definition: BattlenetAccountMgr.cpp:128
TC_GAME_API uint32 GetIdByGameAccount(uint32 gameAccountId)
Definition: BattlenetAccountMgr.cpp:151
static uint32 GetId(std::string const &username)
Definition: AccountMgr.cpp:275
uint32_t uint32
Definition: Define.h:150
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
Definition: LoginDatabase.h:129

+ Here is the call graph for this function:

+ Here is the caller graph for this function:

AccountOpResult Battlenet::AccountMgr::UnlinkGameAccount ( std::string const gameAccountName)
112 {
113  uint32 gameAccountId = GameAccountMgr::GetId(gameAccountName);
114  if (!gameAccountId)
116 
117  if (!GetIdByGameAccount(gameAccountId))
119 
121  stmt->setNull(0);
122  stmt->setNull(1);
123  stmt->setUInt32(2, gameAccountId);
124  LoginDatabase.Execute(stmt);
126 }
void Execute(const char *sql)
Definition: DatabaseWorkerPool.h:87
Definition: PreparedStatement.h:74
LoginDatabaseWorkerPool LoginDatabase
Accessor to the realm/login database.
Definition: DatabaseEnv.cpp:22
TC_GAME_API uint32 GetIdByGameAccount(uint32 gameAccountId)
Definition: BattlenetAccountMgr.cpp:151
static uint32 GetId(std::string const &username)
Definition: AccountMgr.cpp:275
uint32_t uint32
Definition: Define.h:150
PreparedStatement * GetPreparedStatement(PreparedStatementIndex index)
Definition: DatabaseWorkerPool.h:263
void setUInt32(const uint8 index, const uint32 value)
Definition: PreparedStatement.cpp:115
Definition: LoginDatabase.h:129
void setNull(const uint8 index)
Definition: PreparedStatement.cpp:206

+ Here is the call graph for this function:

+ Here is the caller graph for this function: