Fixed the password crash on Windows
authorPerttu Ahola <celeron55@gmail.com>
Wed, 1 Jun 2011 21:01:11 +0000 (00:01 +0300)
committerPerttu Ahola <celeron55@gmail.com>
Wed, 1 Jun 2011 21:01:11 +0000 (00:01 +0300)
src/base64.cpp
src/client.cpp
src/main.cpp
src/server.cpp
src/utility.cpp

index 2a863d161a00e5fcf6c56caf0c088ef6914f1a9e..0dfba501303aa4606232c5f667f35f6ea895b86c 100644 (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 += '=';*/
 
   }
 
index 79bbd8021ca64ba60b2429e67b5ab9a8c4f37c8a..e494056f27dcaeaeb56b75e4082df1423a32012d 100644 (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
index e582569c521548dcc3431d10e91036eaf49c3d37..958f812b3cc64b272f4a11ebba9577f75c334844 100644 (file)
@@ -314,6 +314,7 @@ Fixes to the current release:
 -----------------------------\r
 - Fix client password crash\r
 - Remember to release the fixes (some are already done)\r
+- A command to set one's password when the server is running\r
 \r
 Stuff to do after release:\r
 ---------------------------\r
@@ -1527,6 +1528,8 @@ int main(int argc, char *argv[])
                                g_settings.set("creative_mode", itos(menudata.creative_mode));\r
                                g_settings.set("enable_damage", itos(menudata.enable_damage));\r
                                \r
+                               // NOTE: These are now checked server side; no need to do it\r
+                               //       here, so let's not do it here.\r
                                /*// Check for valid parameters, restart menu if invalid.\r
                                if(playername == "")\r
                                {\r
index acfc7446f18fa6f12f59d8f14920c8086f6e3760..96fcc0d0757a1aa8a78dab959895c4d6b590aba7 100644 (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 "
index 186881c5acc2ba59a794301f457248a202a2a4d4..0721100cb98e845871e033aaf5920fcb9a624a14 100644 (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;