aboutsummaryrefslogtreecommitdiff
path: root/src/server/game/Accounts/AccountMgr.cpp
diff options
context:
space:
mode:
authorAscathor <Break_the_Chain@web.de>2013-07-25 01:49:04 +0200
committerAscathor <Break_the_Chain@web.de>2013-09-01 21:21:16 +0200
commit722a6c143ae9adbab020df4bae4495e612a677ee (patch)
tree834d1e2feebf52c756325902f0abb6dc8291f514 /src/server/game/Accounts/AccountMgr.cpp
parent79d1b7f5439d9f8dacd49847e1e173c8b969171a (diff)
Core/Account: Make account password change security variable and various changes
Settings within worldserver.conf: Three settings for secruity level: 0 - None - No change to current system 1 - Email - Always requires the email entered on registration for confirming. 2 - RBAC - Groups applied with the RBAC role always require the email entered on registration for confirming. RBAC default to every group. Changed some logs to make it more clear what is going on at all. Emails may now no longer exceed 64 chars. Current email is used as regmail. On account creation, two emails are saved. Registration email and normal email. Normal email is relevant afterwards. Registration email can be changed by console ONLY. Includes new commands and changes to existing ones: .account fulfills several new functions: * Still prints GM Level. * If account has permission, it displays the current email. This is not defaulted to any group. * Security level is displayed. Also displays if user has RBAC perm if RBAC security mode is selected .account email allows user to change email with sufficient confirmation .account set sec email allows higher sec with higher sec than account to change the normal email. Registrationemail remains untouched here. .account set sec regmail allows console to change registration email. .pinfo now displays the registration and normal mail. Also fixes .learn all crafts. Closes #10558
Diffstat (limited to 'src/server/game/Accounts/AccountMgr.cpp')
-rw-r--r--src/server/game/Accounts/AccountMgr.cpp85
1 files changed, 83 insertions, 2 deletions
diff --git a/src/server/game/Accounts/AccountMgr.cpp b/src/server/game/Accounts/AccountMgr.cpp
index a9f178685d9..819a3b85fe6 100644
--- a/src/server/game/Accounts/AccountMgr.cpp
+++ b/src/server/game/Accounts/AccountMgr.cpp
@@ -34,21 +34,24 @@ AccountMgr::~AccountMgr()
ClearRBAC();
}
-AccountOpResult AccountMgr::CreateAccount(std::string username, std::string password)
+AccountOpResult AccountMgr::CreateAccount(std::string username, std::string password, std::string email = "")
{
if (utf8length(username) > MAX_ACCOUNT_STR)
return AOR_NAME_TOO_LONG; // username's too long
normalizeString(username);
normalizeString(password);
+ normalizeString(email);
if (GetId(username))
- return AOR_NAME_ALREDY_EXIST; // username does already exist
+ return AOR_NAME_ALREADY_EXIST; // username does already exist
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_INS_ACCOUNT);
stmt->setString(0, username);
stmt->setString(1, CalculateShaPassHash(username, password));
+ stmt->setString(2, email);
+ stmt->setString(3, email);
LoginDatabase.DirectExecute(stmt); // Enforce saving, otherwise AddGroup can fail
@@ -202,6 +205,52 @@ AccountOpResult AccountMgr::ChangePassword(uint32 accountId, std::string newPass
return AOR_OK;
}
+AccountOpResult AccountMgr::ChangeEmail(uint32 accountId, std::string newEmail)
+{
+ std::string username;
+
+ if (!GetName(accountId, username))
+ return AOR_NAME_NOT_EXIST; // account doesn't exist
+
+ if (utf8length(newEmail) > MAX_EMAIL_STR)
+ return AOR_EMAIL_TOO_LONG;
+
+ normalizeString(username);
+ normalizeString(newEmail);
+
+ PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_EMAIL);
+
+ stmt->setString(0, newEmail);
+ stmt->setUInt32(1, accountId);
+
+ LoginDatabase.Execute(stmt);
+
+ return AOR_OK;
+}
+
+AccountOpResult AccountMgr::ChangeRegEmail(uint32 accountId, std::string newEmail)
+{
+ std::string username;
+
+ if (!GetName(accountId, username))
+ return AOR_NAME_NOT_EXIST; // account doesn't exist
+
+ if (utf8length(newEmail) > MAX_EMAIL_STR)
+ return AOR_EMAIL_TOO_LONG;
+
+ normalizeString(username);
+ normalizeString(newEmail);
+
+ PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_UPD_REG_EMAIL);
+
+ stmt->setString(0, newEmail);
+ stmt->setUInt32(1, accountId);
+
+ LoginDatabase.Execute(stmt);
+
+ return AOR_OK;
+}
+
uint32 AccountMgr::GetId(std::string const& username)
{
PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_ACCOUNT_ID_BY_USERNAME);
@@ -245,6 +294,21 @@ bool AccountMgr::GetName(uint32 accountId, std::string& name)
return false;
}
+bool AccountMgr::GetEmail(uint32 accountId, std::string& email)
+{
+ PreparedStatement* stmt = LoginDatabase.GetPreparedStatement(LOGIN_GET_EMAIL_BY_ID);
+ stmt->setUInt32(0, accountId);
+ PreparedQueryResult result = LoginDatabase.Query(stmt);
+
+ if (result)
+ {
+ email = (*result)[0].GetString();
+ return true;
+ }
+
+ return false;
+}
+
bool AccountMgr::CheckPassword(uint32 accountId, std::string password)
{
std::string username;
@@ -263,6 +327,23 @@ bool AccountMgr::CheckPassword(uint32 accountId, std::string password)
return (result) ? true : false;
}
+bool AccountMgr::CheckEmail(uint32 accountId, std::string newEmail)
+{
+ std::string oldEmail;
+
+ // We simply return false for a non-existing email
+ if (!GetEmail(accountId, oldEmail))
+ return false;
+
+ normalizeString(oldEmail);
+ normalizeString(newEmail);
+
+ if (strcmp(oldEmail.c_str(), newEmail.c_str()) == 0)
+ return true;
+
+ return false;
+}
+
uint32 AccountMgr::GetCharactersCount(uint32 accountId)
{
// check character count