public function login($user, $pass, $maxtimeout = 10) {
        try {
            $this->expect('((U|u)ser|(L|l)ogin)((N|n)ame|)(:|)', $user);
            $this->expect('(P|p)ass((W|w)ord|)(:|)', $pass);
        } catch (TelnetException $e) {
            throw new TelnetException('Could not find password request. Login failed.');
        }

        $timestart = time();
        $buff = '';
        while (true) {
            $buff = $this->recvLine();
            $timerun = time() - $timestart;

            if (preg_match("/(fail|wrong|incorrect|failed)/i", $buff)) {
                throw new TelnetException("Username or password wrong! Login failed");
            }

            if (preg_match("/(#|>|\$)/", $buff)) {
                break;
            }

            if ($timerun >= $maxtimeout) {
                throw new TelnetException("Could not get reply from device. Login failed.");
            }
        }

        $this->recvAll();
        $lines = explode("\n", $this->getBuffer());
        $prompt = array_slice($lines, -1);
        $this->prompt = $prompt[0];
        return $this;
    }