Login function. Creates session and returns the token or an error code with an error and message.