/// \brief Modify the attributes of an Account in the database /// /// @param account Atlas description of the Account to be modified /// @param accountId String identifier of the Account to be modified bool Storage::modAccount(const Atlas::Message::MapType & account, const std::string & accountId) { std::string columns; bool empty = true; Atlas::Message::MapType::const_iterator I = account.find("type"); if (I != account.end() && I->second.isString()) { empty = false; columns += "type = '"; columns += I->second.String(); columns += "'"; } I = account.find("password"); if (I != account.end() && I->second.isString()) { if (!empty) { columns += ", "; } std::string hash; encrypt_password(I->second.String(), hash); columns += "password = '******'"; } return m_connection.updateSimpleRow("accounts", "username", accountId, columns); }
Socket login( Socket aSocket, Crypto *crypto, AccountInfo acct_info ) { Socket g_socket( crypto ); CPacket loginPacket = { { 52, 1051 }, { 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00 } }; CPacket packet; char g_address[16]; strncpy( loginPacket.data, acct_info.username, 16 ); encrypt_password( &loginPacket.data[16], acct_info.password ); strncpy( ( loginPacket.data + 32 ), acct_info.servername, 16 ); /* Send the login Packet */ aSocket.send_packet( loginPacket ); /* Read the incoming packet's header */ packet = aSocket.read_packet(); account_id = *( int * )packet.data; /* Copy the game server's IP into the ipBuffer */ strcpy( g_address, ( const char * )( packet.data + 0x08 ) ); /* Generate keys three and four */ crypto->generate_keys( packet ); /* Connect to the game server */ if ( !g_socket.connect( g_address, GAMESERVERPORT ) ) { std::cout << "Error connecting to game server..." << std::endl; return g_socket; } /* Clear the address from the packet we recieved from the account server */ memset( ( void * )( packet.data + 0x08 ), 0, ( ( packet.header.size - sizeof( CPacketHeader ) ) - 8 ) ); /* Copy the blacknull string into the packet */ strcpy( ( packet.data + 0x08 ), "blacknull" ); /* Reset the counters */ crypto->reset_counters(); /* Send the connecting packet to the game server */ g_socket.send_packet( packet ); /* Use new keys */ crypto->use_new_keys(); printf( "Connected...\n"); /* Return the game server socket */ return g_socket; }
void save_salt_to_mcu(void) { //volatile salt_t *salt = &SALT_STRUCT; uint32_t temp_encypted_password[8] = {0}; uint8_t i; memcpy((uint8_t *)Stored_values_ram.salt, (const uint8_t *)var_Salt.index, 32); encrypt_password(temp_password1, temp_encypted_password); memcpy((uint8_t *)Stored_values_ram.unlock_password, (const uint8_t *)temp_encypted_password, 32); Calculate_block_crc(); Update_stored_values(); }
/// \brief Store a new Account in the database /// /// @param account Atlas description of Account to be stored bool Storage::putAccount(const Atlas::Message::MapType & account) { Atlas::Message::MapType::const_iterator I = account.find("username"); if (I == account.end() || !I->second.isString()) { return false; } const std::string & username = I->second.String(); I = account.find("password"); if (I == account.end() || !I->second.isString()) { return false; } const std::string & password = I->second.String(); std::string hash; encrypt_password(password, hash); std::string type = "player"; I = account.find("type"); if (I != account.end() && I->second.isString()) { type = I->second.String(); } std::string columns = "username, type, password"; std::string values = "'"; values += username; values += "', '"; values += type; values += "', '"; values += hash; values += "'"; std::string id; if (m_connection.newId(id) < 0) { return false; } return m_connection.createSimpleRow("accounts", id, columns, values); }