The king password is unique for every Tamagotchi. The purpose of the Username you make up on your Tamagotchi when you first play with it, is to get special passwords that only work on the exact Username.
Yeah it only works if the usernames are the same and if they are then there might be a chance that you will get the password if someone does have the same username as you.