Fixed the password crash on Windows

master
Perttu Ahola 2011-06-02 00:01:11 +03:00
parent bbead93c1a
commit 51cf464f74
5 changed files with 18 additions and 8 deletions

View File

@ -71,9 +71,10 @@ std::string base64_encode(unsigned char const* bytes_to_encode, unsigned int in_
for (j = 0; (j < i + 1); j++)
ret += base64_chars[char_array_4[j]];
while((i++ < 3))
ret += '=';
// Don't pad it with =
/*while((i++ < 3))
ret += '=';*/
}

View File

@ -306,8 +306,14 @@ void Client::step(float dtime)
SharedBuffer<u8> data(2+1+PLAYERNAME_SIZE+PASSWORD_SIZE);
writeU16(&data[0], TOSERVER_INIT);
writeU8(&data[2], SER_FMT_VER_HIGHEST);
memset((char*)&data[3], 0, PLAYERNAME_SIZE);
snprintf((char*)&data[3], PLAYERNAME_SIZE, "%s", myplayer->getName());
/*dstream<<"Client: password hash is \""<<m_password<<"\""
<<std::endl;*/
memset((char*)&data[23], 0, PASSWORD_SIZE);
snprintf((char*)&data[23], PASSWORD_SIZE, "%s", m_password.c_str());
// Send as unreliable

View File

@ -314,6 +314,7 @@ Fixes to the current release:
-----------------------------
- Fix client password crash
- Remember to release the fixes (some are already done)
- A command to set one's password when the server is running
Stuff to do after release:
---------------------------
@ -1527,6 +1528,8 @@ int main(int argc, char *argv[])
g_settings.set("creative_mode", itos(menudata.creative_mode));
g_settings.set("enable_damage", itos(menudata.enable_damage));
// NOTE: These are now checked server side; no need to do it
// here, so let's not do it here.
/*// Check for valid parameters, restart menu if invalid.
if(playername == "")
{

View File

@ -1923,7 +1923,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id)
checkpwd = g_settings.get("default_password");
}
if(password != checkpwd)
if(password != checkpwd && checkpwd != "")
{
derr_server<<DTIME<<"Server: peer_id="<<peer_id
<<": supplied invalid password for "

View File

@ -229,10 +229,10 @@ std::string translatePassword(std::string playername, std::wstring password)
if(password.length() == 0)
return "";
std::string slt=playername + wide_to_narrow(password);
SHA1 *sha1 = new SHA1();
sha1->addBytes(slt.c_str(), slt.length());
unsigned char *digest = sha1->getDigest();
std::string slt = playername + wide_to_narrow(password);
SHA1 sha1;
sha1.addBytes(slt.c_str(), slt.length());
unsigned char *digest = sha1.getDigest();
std::string pwd = base64_encode(digest, 20);
free(digest);
return pwd;