Use "plain" auth if and only if username and password are provided. Parse port from "host" field if it's provided.