From d4d49ee8f4d425e7a4136d65f519728869680951 Mon Sep 17 00:00:00 2001 From: Ciaran Gultnieks Date: Fri, 20 May 2011 20:28:03 +0100 Subject: Passwords - password entry at main menu, stored and checked by server --- src/main.cpp | 27 +++++++++++++++++++++++++++ 1 file changed, 27 insertions(+) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 5d607b2d8..0b181a36d 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -325,6 +325,8 @@ Making it more portable: #include "materials.h" #include "game.h" #include "keycode.h" +#include "sha1.h" +#include "base64.h" // This makes textures ITextureSource *g_texturesource = NULL; @@ -1170,6 +1172,7 @@ int main(int argc, char *argv[]) return 0; } + /* More parameters */ @@ -1324,11 +1327,15 @@ int main(int argc, char *argv[]) */ std::wstring error_message = L""; + // The password entered during the menu screen, + std::string password; + /* Menu-game loop */ while(device->run() && kill == false) { + // This is used for catching disconnects try { @@ -1428,6 +1435,25 @@ int main(int argc, char *argv[]) } playername = wide_to_narrow(menudata.name); + + // Get an sha-1 hash of the player's name combined with + // the password entered. That's what the server uses as + // their password. (Exception : if the password field is + // blank, we send a blank password - this is for backwards + // compatibility with password-less players). + if(menudata.password.length() > 0) + { + std::string slt=playername + wide_to_narrow(menudata.password); + SHA1 *sha1 = new SHA1(); + sha1->addBytes(slt.c_str(), slt.length()); + unsigned char *digest = sha1->getDigest(); + password = base64_encode(digest, 20); + } + else + { + password = ""; + } + address = wide_to_narrow(menudata.address); int newport = stoi(wide_to_narrow(menudata.port)); if(newport != 0) @@ -1474,6 +1500,7 @@ int main(int argc, char *argv[]) font, map_dir, playername, + password, address, port, error_message -- cgit v1.2.3 From 52d857cf1527948e1db5eead457e51b6741de8a2 Mon Sep 17 00:00:00 2001 From: Ciaran Gultnieks Date: Fri, 20 May 2011 21:37:13 +0100 Subject: Passwords - a few corrections to the previous commit --- src/main.cpp | 1 + src/server.cpp | 2 +- src/sha1.cpp | 20 ++++++++++++++++++-- src/sha1.h | 20 ++++++++++++++++++-- 4 files changed, 38 insertions(+), 5 deletions(-) (limited to 'src/main.cpp') diff --git a/src/main.cpp b/src/main.cpp index 0b181a36d..184643b9f 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -1448,6 +1448,7 @@ int main(int argc, char *argv[]) sha1->addBytes(slt.c_str(), slt.length()); unsigned char *digest = sha1->getDigest(); password = base64_encode(digest, 20); + free(digest); } else { diff --git a/src/server.cpp b/src/server.cpp index 051ca85fb..b5cb48a36 100644 --- a/src/server.cpp +++ b/src/server.cpp @@ -1780,7 +1780,7 @@ void Server::ProcessData(u8 *data, u32 datasize, u16 peer_id) if(datasize == 2+1+PLAYERNAME_SIZE) { // old version - assume blank password - *password = 0; + password[0] = 0; } else { diff --git a/src/sha1.cpp b/src/sha1.cpp index 93df10969..98180adc7 100644 --- a/src/sha1.cpp +++ b/src/sha1.cpp @@ -4,8 +4,24 @@ Copyright (c) 2005 Michael D. Leonhard http://tamale.net/ -This file is licensed under the terms described in the -accompanying LICENSE file. +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + */ #include diff --git a/src/sha1.h b/src/sha1.h index 2f92fe8d1..c04947373 100644 --- a/src/sha1.h +++ b/src/sha1.h @@ -4,8 +4,24 @@ Copyright (c) 2005 Michael D. Leonhard http://tamale.net/ -This file is licensed under the terms described in the -accompanying LICENSE file. +Permission is hereby granted, free of charge, to any person obtaining a copy of +this software and associated documentation files (the "Software"), to deal in +the Software without restriction, including without limitation the rights to +use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies +of the Software, and to permit persons to whom the Software is furnished to do +so, subject to the following conditions: + +The above copyright notice and this permission notice shall be included in all +copies or substantial portions of the Software. + +THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR +IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, +FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE +AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER +LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, +OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE +SOFTWARE. + */ #ifndef SHA1_HEADER -- cgit v1.2.3