コード例 #1
0
ファイル: __init__.py プロジェクト: jhmscott/OctoPrint-LDAP
    def checkPassword(self, username, password):
        try:
            connection = self.getLDAPClient()

            username = self.escapeLDAP(username)
            dn = self.findLDAPUser(username)
            if dn is None:
                return False
            connection.bind_s(dn, password)
            connection.unbind_s()

            user = FilebasedUserManager.findUser(self, username)
            if not user:
                self._logger.debug("Add new user")
                self.addUser(username, str(uuid.uuid4()), True)
            return True

        except ldap.INVALID_CREDENTIALS:
            self._logger.error("LDAP : Your username or password is incorrect.")
            return FilebasedUserManager.checkPassword(self, username, password)
        except ldap.LDAPError, e:
            if type(e.message) == dict:
                for (k, v) in e.message.iteritems():
                    self._logger.error("%s: %sn" % (k, v))
            else:
                self._logger.error(e.message)
                return False
コード例 #2
0
    def checkPassword(self, username, password):
        if self.local_enabled:
            user = super(FabmanUserManager, self).findUser(username)
            if user is not None and not isinstance(user, FabmanUser):
                return FilebasedUserManager.checkPassword(
                    self, username, password)

        if not self.fabman_enabled:
            return False

        return self._fabman_auth(username, password)