54 memset(salted_password, 0, sizeof(salted_password)); |
54 memset(salted_password, 0, sizeof(salted_password)); |
55 snprintf(salted_password, sizeof(salted_password), "%s", password); |
55 snprintf(salted_password, sizeof(salted_password), "%s", password); |
56 /* Add the game seed and the server's unique ID as the salt. */ |
56 /* Add the game seed and the server's unique ID as the salt. */ |
57 for (uint i = 0; i < NETWORK_UNIQUE_ID_LENGTH; i++) salted_password[i] ^= _password_server_unique_id[i] ^ (_password_game_seed >> i); |
57 for (uint i = 0; i < NETWORK_UNIQUE_ID_LENGTH; i++) salted_password[i] ^= _password_server_unique_id[i] ^ (_password_game_seed >> i); |
58 |
58 |
59 md5_state_t state; |
59 Md5 checksum; |
60 md5_byte_t digest[16]; |
60 uint8 digest[16]; |
61 static char hashed_password[NETWORK_UNIQUE_ID_LENGTH]; |
61 static char hashed_password[NETWORK_UNIQUE_ID_LENGTH]; |
62 |
62 |
63 /* Generate the MD5 hash */ |
63 /* Generate the MD5 hash */ |
64 md5_init(&state); |
64 checksum.Append((const uint8*)salted_password, sizeof(salted_password)); |
65 md5_append(&state, (const md5_byte_t*)salted_password, sizeof(salted_password)); |
65 checksum.Finish(digest); |
66 md5_finish(&state, digest); |
|
67 |
66 |
68 for (int di = 0; di < 16; di++) sprintf(hashed_password + di * 2, "%02x", digest[di]); |
67 for (int di = 0; di < 16; di++) sprintf(hashed_password + di * 2, "%02x", digest[di]); |
69 |
68 |
70 return hashed_password; |
69 return hashed_password; |
71 } |
70 } |