Implement authenticate function.