The writing part is OK, though a bit redundand - why do you first send the length+2 and then the length again for each string? There *might* be a good reason for this, but your receiving code doesn't look like that applies.
The receiving code has several issues though. After looking at it for a bit I think I understand where you are coming from, but you seem to have some misconceptions about how TCP behaves, and what the functions do.
First off, a TCP connection is a stream of bytes. If you want to use it to send separate *messages*, there is no way to tell where one message starts and ends unless you provide a way yourself, e.g. saying how long each message is.
I'm guessing that your while loop is intended to receive several blocks of username+password, so it would loop until they have all been received. However, that won't work reliably, because as I said TCP itself doesn't have a way to tell where the message ends. If you send two usernames and passwords, you won't know when to stop reading them unless you e.g. send the count beforehand. The code you wrote might only get one of the pairs, or it might get all two and then also start consuming the next thing that was sent, because it has already arrived.
Very related, you have to assume that any call to tcp_receive can fail because the data you wait for has not arrived yet. Yes, even if you sent that data in one call to socket_send. You can send "Hello World" and then "How are you" and receive it as "Hello Wo" "rldHow a" "re you", or as "Hello WorldHow are you" or really split up in any way. So if you just received "Hello" you can't assume that "World" has already arrived as well. You have two calls to tcp_receive within your loop where you don't actually check if the data was received or not. That is always an error, as I just explained.
All that said, I think your immediate problem is that you don't try to receive the second length header, e.g. you would need another tcp_receive(socket, 2) below "// get password". However, I hope I made clear that the code is still badly broken if you fix this problem, even though it will probably work most of the time on your local network.