MongoDBUtils.authenticate method for authentication. Code duplicates removed.