public function login($username, $password) {
        $credentials = array(
            'lgname' => $username,
            'lgpassword' => $password
        );
        $firstlogin = $this->client->login($credentials);
        $this->failOnError("Wiki login failed.", $firstlogin);
        $resultMsg = $firstlogin['login']['result'];
        if ($resultMsg != "NeedToken" && $resultMsg != "Success") {
            throw new SessionException("Wiki login failed: $resultMsg");
        }
        
        if ($resultMsg == "NeedToken") {
            $secondLogin = $this->client->login(array_merge(array(
                'lgtoken' => $firstlogin['login']['token']
            ), $credentials));
            $this->failOnError("Wiki login failed.", $secondLogin);
            $resultMsg = $secondLogin['login']['result'];
            if ($resultMsg != "Success") {
                throw new SessionException("Wiki login failed: $resultMsg");
            }
            $this->tokencache['login'] =  $firstlogin['login']['token'];
        }
    }