public function login(string $username, string $password, Session $session)
    {
        if ($session->has('authentication', 'user_id'))
        {
            throw new AuthenticationError(
                "Already logged in",
                AuthenticationError::DUPLICATE_SESSION
            );
        }

        $cl = $this->getUserClass();
        $this->user = new $cl;
        try
        {
            $this->user->obtainFromLogin($username, $password);
        }
        catch (AuthenticationError $e)
        {
            throw $e;
        }
        catch (\Exception $e)
        {
            throw new AuthenticationError("Login failed", $e->getCode(), $e); 
        }

        $session->set('authentication', 'user_id', $this->user->getUserID());
        return $this->user;
    }