Implemented most of the authentication service.