Modified to account for both username/password and apikey login and validation