You'll need to connect to the room first to be able to verify the password with the host. If it doesn't match, then disconnect.
Otherwise, you'll need an intermediate (matchmaking) lobby/server that has all the rooms and passwords that peers must first connect and validate with before joining further rooms.