refactor checkCredentials to reduce redundancy