# Path: flumotion/common/log.py
# def init():


from twisted.cred import checkers
from twisted.internet import defer
from twisted.python import failure
from zope.interface import implements
from flumotion.common import log, errors
from flumotion.twisted import credentials

    def addUser(self, username, password):
        self.users[username] = password

    def _cbPasswordMatch(self, matched, username, avatarId):
        if matched:
            return avatarId or username
        else:
            return failure.Failure(errors.NotAuthenticatedError())

    ### ICredentialsChecker interface methods

    def requestAvatarId(self, credentials):
        avatarId = getattr(credentials, 'avatarId', None)

        if self._passwordless:
            self.debug('allowing passwordless login for user %s',
                       credentials.username)
            return defer.succeed(avatarId or credentials.username)
        elif credentials.username in self.users:
            self.debug('authenticating user %s' % credentials.username)
            return defer.maybeDeferred(
                credentials.checkPassword,
                self.users[credentials.username]).addCallback(
                self._cbPasswordMatch, str(credentials.username),
                avatarId)
        else:
            return defer.fail(errors.NotAuthenticatedError())



# Path: flumotion/common/log.py
# def init():


# Path: flumotion/twisted/checkers.py
from twisted.cred import checkers
from twisted.internet import defer
from twisted.python import failure
from zope.interface import implements
from flumotion.common import log, errors
from flumotion.twisted import credentials


    def addUser(self, username, password):
        self.users[username] = password

    def _cbPasswordMatch(self, matched, username, avatarId):
        if matched:
            return avatarId or username
        else:
            return failure.Failure(errors.NotAuthenticatedError())

    ### ICredentialsChecker interface methods

    def requestAvatarId(self, credentials):
        avatarId = getattr(credentials, 'avatarId', None)

        if self._passwordless:
            self.debug('allowing passwordless login for user %s',
                       credentials.username)
            return defer.succeed(avatarId or credentials.username)
        elif credentials.username in self.users:
            self.debug('authenticating user %s' % credentials.username)
            return defer.maybeDeferred(
                credentials.checkPassword,
                self.users[credentials.username]).addCallback(
                self._cbPasswordMatch, str(credentials.username),
                avatarId)
        else:
            return defer.fail(errors.NotAuthenticatedError())



class CryptChecker(log.Loggable):