'Checks to see if authentication was good. Called once the info has
been retrieved from the DB.'

def _cbAuthenticate(self, result, credentials, deferred):

    if (len(result) == 0):
        deferred.errback(error.UnauthorizedLogin('Username    unknown'))
    else:
        (username, password) = result[0]
        if self.customCheckFunc:
            if self.customCheckFunc(username, credentials.password, password):
                deferred.callback(credentials.username)
            else:
                deferred.errback(error.UnauthorizedLogin('Password    mismatch'))
        elif IUsernameHashedPassword.providedBy(credentials):
            if credentials.checkPassword(password):
                deferred.callback(credentials.username)
            else:
                deferred.errback(error.UnauthorizedLogin('Password    mismatch'))
        elif IUsernamePassword.providedBy(credentials):
            if self.caseSensitivePasswords:
                passOk = (password.lower() == credentials.password.lower())
            else:
                passOk = (password == credentials.password)
            if passOk:
                deferred.callback(credentials.username)
            else:
                deferred.errback(error.UnauthorizedLogin('Password    mismatch'))
        else:
            deferred.errback(error.UnhandledCredentials())
