EvEmu  0.8.4
11 September 2021
 All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Modules Pages
PasswordModuleTest.cpp
Go to the documentation of this file.
1 /*
2  ------------------------------------------------------------------------------------
3  LICENSE:
4  ------------------------------------------------------------------------------------
5  This file is part of EVEmu: EVE Online Server Emulator
6  Copyright 2006 - 2021 The EVEmu Team
7  For the latest information visit https://evemu.dev
8  ------------------------------------------------------------------------------------
9  This program is free software; you can redistribute it and/or modify it under
10  the terms of the GNU Lesser General Public License as published by the Free Software
11  Foundation; either version 2 of the License, or (at your option) any later
12  version.
13 
14  This program is distributed in the hope that it will be useful, but WITHOUT
15  ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
16  FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public License for more details.
17 
18  You should have received a copy of the GNU Lesser General Public License along with
19  this program; if not, write to the Free Software Foundation, Inc., 59 Temple
20  Place - Suite 330, Boston, MA 02111-1307, USA, or go to
21  http://www.gnu.org/copyleft/lesser.txt.
22  ------------------------------------------------------------------------------------
23  Author: Bloody.Rabbit
24 */
25 
26 #include "eve-test.h"
27 
28 // username
29 const std::string USERNAME = " Hello World ";
30 // password
31 const std::string PASSWORD = " Secret Password ";
32 // hash
33 const uint8 HASH[] =
34 {
35  0x1b, 0xe6, 0xdf, 0x86, 0x42, 0x1d, 0xcf, 0x2c,
36  0xfa, 0x71, 0x90, 0x0f, 0x34, 0x27, 0x75, 0xb0,
37  0x31, 0x98, 0xdc, 0xe5
38 };
39 const size_t HASH_LEN = sizeof( HASH );
40 
41 int auth_PasswordModuleTest( int argc, char* argv[] )
42 {
43  // Print input data
44  ::printf( "username='%s' (len=%lu)\n"
45  "password='%s' (len=%lu)\n",
46  USERNAME.c_str(), USERNAME.length(),
47  PASSWORD.c_str(), PASSWORD.length() );
48 
49  // Generate the hash
50  std::string hash;
52  USERNAME, PASSWORD, hash ) )
53  {
54  ::fprintf( stderr, "Cannot generate the hash" );
55  return EXIT_FAILURE;
56  }
57 
58  // Compare the lengths
59  if( HASH_LEN != hash.length()
60  // Compare the hashes
61  || 0 != ::memcmp( hash.c_str(), HASH, HASH_LEN ) )
62  {
63  ::fprintf( stderr, "The computed and the reference"
64  " hashes do not match" );
65  return EXIT_FAILURE;
66  }
67 
68  ::puts( "Hash computation OK" );
69  return EXIT_SUCCESS;
70 }
unsigned __int8 uint8
Definition: eve-compat.h:46
const std::string PASSWORD
const std::string USERNAME
const size_t HASH_LEN
static bool GeneratePassHash(const std::string &user, const std::string &pass, std::string &hash)
Generates a SHA-1 hash from a username and a password.
int auth_PasswordModuleTest(int argc, char *argv[])
const uint8 HASH[]