Added login and token validation for API use