mirror of
https://github.com/minetest/minetest.git
synced 2024-11-24 00:23:46 +01:00
Refactor around translatePassword
Change types for passed password from wstring to string, which removes converting back and forth in most cases. Move the narrow_to_wide conversion, where its neccessary, closer to irrlicht. Remove trailing spaces in guiPasswordChange.cpp. Make parameters for translatePassword passed as const reference.
This commit is contained in:
parent
821d0025da
commit
f0a1379e5a
@ -1062,8 +1062,8 @@ void Client::sendChatMessage(const std::wstring &message)
|
|||||||
Send(&pkt);
|
Send(&pkt);
|
||||||
}
|
}
|
||||||
|
|
||||||
void Client::sendChangePassword(const std::wstring &oldpassword,
|
void Client::sendChangePassword(const std::string &oldpassword,
|
||||||
const std::wstring &newpassword)
|
const std::string &newpassword)
|
||||||
{
|
{
|
||||||
Player *player = m_env.getLocalPlayer();
|
Player *player = m_env.getLocalPlayer();
|
||||||
if(player == NULL)
|
if(player == NULL)
|
||||||
|
@ -407,8 +407,8 @@ public:
|
|||||||
const std::map<std::string, std::string> &fields);
|
const std::map<std::string, std::string> &fields);
|
||||||
void sendInventoryAction(InventoryAction *a);
|
void sendInventoryAction(InventoryAction *a);
|
||||||
void sendChatMessage(const std::wstring &message);
|
void sendChatMessage(const std::wstring &message);
|
||||||
void sendChangePassword(const std::wstring &oldpassword,
|
void sendChangePassword(const std::string &oldpassword,
|
||||||
const std::wstring &newpassword);
|
const std::string &newpassword);
|
||||||
void sendDamage(u8 damage);
|
void sendDamage(u8 damage);
|
||||||
void sendBreath(u16 breath);
|
void sendBreath(u16 breath);
|
||||||
void sendRespawn();
|
void sendRespawn();
|
||||||
|
@ -392,7 +392,7 @@ bool ClientLauncher::launch_game(std::string &error_message,
|
|||||||
else
|
else
|
||||||
playername = menudata.name;
|
playername = menudata.name;
|
||||||
|
|
||||||
password = translatePassword(playername, narrow_to_wide(menudata.password));
|
password = translatePassword(playername, menudata.password);
|
||||||
|
|
||||||
g_settings->set("name", playername);
|
g_settings->set("name", playername);
|
||||||
|
|
||||||
|
@ -203,7 +203,8 @@ bool GUIPasswordChange::acceptInput()
|
|||||||
e->setVisible(true);
|
e->setVisible(true);
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
m_client->sendChangePassword(oldpass, newpass);
|
m_client->sendChangePassword(wide_to_narrow(oldpass),
|
||||||
|
wide_to_narrow(newpass));
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -267,8 +267,8 @@ void Server::handleCommand_Auth(NetworkPacket* pkt)
|
|||||||
DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_EMPTY_PASSWORD);
|
DenyAccess(pkt->getPeerId(), SERVER_ACCESSDENIED_EMPTY_PASSWORD);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::wstring raw_default_password =
|
std::string raw_default_password =
|
||||||
narrow_to_wide(g_settings->get("default_password"));
|
g_settings->get("default_password");
|
||||||
std::string initial_password =
|
std::string initial_password =
|
||||||
translatePassword(playername, raw_default_password);
|
translatePassword(playername, raw_default_password);
|
||||||
|
|
||||||
@ -571,8 +571,8 @@ void Server::handleCommand_Init_Legacy(NetworkPacket* pkt)
|
|||||||
L"disallowed. Set a password and try again.");
|
L"disallowed. Set a password and try again.");
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
std::wstring raw_default_password =
|
std::string raw_default_password =
|
||||||
narrow_to_wide(g_settings->get("default_password"));
|
g_settings->get("default_password");
|
||||||
std::string initial_password =
|
std::string initial_password =
|
||||||
translatePassword(playername, raw_default_password);
|
translatePassword(playername, raw_default_password);
|
||||||
|
|
||||||
|
@ -255,8 +255,7 @@ int ModApiUtil::l_get_password_hash(lua_State *L)
|
|||||||
NO_MAP_LOCK_REQUIRED;
|
NO_MAP_LOCK_REQUIRED;
|
||||||
std::string name = luaL_checkstring(L, 1);
|
std::string name = luaL_checkstring(L, 1);
|
||||||
std::string raw_password = luaL_checkstring(L, 2);
|
std::string raw_password = luaL_checkstring(L, 2);
|
||||||
std::string hash = translatePassword(name,
|
std::string hash = translatePassword(name, raw_password);
|
||||||
narrow_to_wide(raw_password));
|
|
||||||
lua_pushstring(L, hash.c_str());
|
lua_pushstring(L, hash.c_str());
|
||||||
return 1;
|
return 1;
|
||||||
}
|
}
|
||||||
|
@ -181,12 +181,13 @@ std::string wide_to_narrow(const std::wstring &wcs)
|
|||||||
// their password. (Exception : if the password field is
|
// their password. (Exception : if the password field is
|
||||||
// blank, we send a blank password - this is for backwards
|
// blank, we send a blank password - this is for backwards
|
||||||
// compatibility with password-less players).
|
// compatibility with password-less players).
|
||||||
std::string translatePassword(std::string playername, std::wstring password)
|
std::string translatePassword(const std::string &playername,
|
||||||
|
const std::string &password)
|
||||||
{
|
{
|
||||||
if (password.length() == 0)
|
if (password.length() == 0)
|
||||||
return "";
|
return "";
|
||||||
|
|
||||||
std::string slt = playername + wide_to_narrow(password);
|
std::string slt = playername + password;
|
||||||
SHA1 sha1;
|
SHA1 sha1;
|
||||||
sha1.addBytes(slt.c_str(), slt.length());
|
sha1.addBytes(slt.c_str(), slt.length());
|
||||||
unsigned char *digest = sha1.getDigest();
|
unsigned char *digest = sha1.getDigest();
|
||||||
|
@ -43,7 +43,8 @@ wchar_t *narrow_to_wide_c(const char *str);
|
|||||||
|
|
||||||
std::wstring narrow_to_wide(const std::string &mbs);
|
std::wstring narrow_to_wide(const std::string &mbs);
|
||||||
std::string wide_to_narrow(const std::wstring &wcs);
|
std::string wide_to_narrow(const std::wstring &wcs);
|
||||||
std::string translatePassword(std::string playername, std::wstring password);
|
std::string translatePassword(const std::string &playername,
|
||||||
|
const std::string &password);
|
||||||
std::string urlencode(std::string str);
|
std::string urlencode(std::string str);
|
||||||
std::string urldecode(std::string str);
|
std::string urldecode(std::string str);
|
||||||
u32 readFlagString(std::string str, const FlagDesc *flagdesc, u32 *flagmask);
|
u32 readFlagString(std::string str, const FlagDesc *flagdesc, u32 *flagmask);
|
||||||
|
Loading…
Reference in New Issue
Block a user