Пример #1
0
    def login(self, password, *ident):
        # send login packet
        resp = self.sendRequest(C.MANAGER_ID, []).result()
        challenge = resp[0][1] # get password challenge

        # send password response
        if password is None:
            password = support.get_password(self.host, self.port)
        m = hashlib.md5()
        m.update(challenge)
        m.update(password)
        try:
            resp = self.sendRequest(C.MANAGER_ID, [(0L, m.digest())]).result()
        except Exception:
            raise LoginFailedError('Incorrect password.')
        support.cache_password(self.host, self.port, password)
        self.password = password
        self.loginMessage = resp[0][1] # get welcome message

        # send identification
        try:
            resp = self.sendRequest(C.MANAGER_ID, [(0L, (1L,) + ident)]).result()
        except Exception:
            raise LoginFailedError('Bad identification.')
        return resp[0][1] # get assigned ID
Пример #2
0
    def authenticate(self, password):
        """Authenticate to the manager using the given password."""
        # send login packet
        resp = yield self.sendRequest(C.MANAGER_ID, [])
        challenge = resp[0][1] # get password challenge

        if password is None:
            password = support.get_password(self.host, self.port)

        # send password response
        m = hashlib.md5()
        m.update(challenge)
        m.update(password)
        try:
            resp = yield self.sendRequest(C.MANAGER_ID, [(0L, m.digest())])
        except Exception:
            raise errors.LoginFailedError('Incorrect password.')
        support.cache_password(self.host, self.port, password)
        self.password = password
        self.loginMessage = resp[0][1] # get welcome message