From 51cf464f7450ee31e3a986b521f90cc6195bb2fb Mon Sep 17 00:00:00 2001 From: Perttu Ahola Date: Thu, 2 Jun 2011 00:01:11 +0300 Subject: [PATCH] Fixed the password crash on Windows --- src/base64.cpp | 7 ++++--- src/client.cpp | 6 ++++++ src/main.cpp | 3 +++ src/server.cpp | 2 +- src/utility.cpp | 8 ++++---- 5 files changed, 18 insertions(+), 8 deletions(-) diff --git a/src/base64.cpp b/src/base64.cpp index 2a863d16..0dfba501 100644 --- a/src/base64.cpp +++ b/src/base64.cpp @@ -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 += '=';*/ } diff --git a/src/client.cpp b/src/client.cpp index 79bbd802..e494056f 100644 --- a/src/client.cpp +++ b/src/client.cpp @@ -306,8 +306,14 @@ void Client::step(float dtime) SharedBuffer 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 \""<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; -- 2.30.2