twisted.cred.checkers.FilePasswordDB

Here are the examples of the python api twisted.cred.checkers.FilePasswordDB taken from open source projects. By voting up you can indicate which examples are most useful and appropriate.

17 Examples 7

Example 1

Project: mythbox Source File: cred_file.py
Function: generatechecker
    def generateChecker(self, argstring):
        """
        This checker factory expects to get the location of a file.
        The file should conform to the format required by
        L{FilePasswordDB} (using defaults for all
        initialization parameters).
        """
        from twisted.python.filepath import FilePath
        if not argstring.strip():
            raise ValueError, '%r requires a filename' % self.authType
        elif not FilePath(argstring).isfile():
            self.errorOutput.write('%s: %s\n' % (invalidFileWarning, argstring))
        return FilePasswordDB(argstring)

Example 2

Project: mythbox Source File: test_newcred.py
Function: test_user_lookup
    def testUserLookup(self):
        dbfile = self.mktemp()
        db = checkers.FilePasswordDB(dbfile)
        f = file(dbfile, 'w')
        for (u, p) in self.users:
            f.write('%s:%s\n' % (u, p))
        f.close()

        for (u, p) in self.users:
            self.failUnlessRaises(KeyError, db.getUser, u.upper())
            self.assertEquals(db.getUser(u), (u, p))

Example 3

Project: mythbox Source File: test_newcred.py
Function: test_case_insensitivity
    def testCaseInSensitivity(self):
        dbfile = self.mktemp()
        db = checkers.FilePasswordDB(dbfile, caseSensitive=0)
        f = file(dbfile, 'w')
        for (u, p) in self.users:
            f.write('%s:%s\n' % (u, p))
        f.close()

        for (u, p) in self.users:
            self.assertEquals(db.getUser(u.upper()), (u, p))

Example 4

Project: mythbox Source File: test_newcred.py
Function: test_request_avatar_id
    def testRequestAvatarId(self):
        dbfile = self.mktemp()
        db = checkers.FilePasswordDB(dbfile, caseSensitive=0)
        f = file(dbfile, 'w')
        for (u, p) in self.users:
            f.write('%s:%s\n' % (u, p))
        f.close()
        creds = [credentials.UsernamePassword(u, p) for u, p in self.users]
        d = defer.gatherResults(
            [defer.maybeDeferred(db.requestAvatarId, c) for c in creds])
        d.addCallback(self.assertEquals, [u for u, p in self.users])
        return d

Example 5

Project: mythbox Source File: test_newcred.py
Function: testrequestavatarid_hashed
    def testRequestAvatarId_hashed(self):
        dbfile = self.mktemp()
        db = checkers.FilePasswordDB(dbfile, caseSensitive=0)
        f = file(dbfile, 'w')
        for (u, p) in self.users:
            f.write('%s:%s\n' % (u, p))
        f.close()
        creds = [credentials.UsernameHashedPassword(u, p) for u, p in self.users]
        d = defer.gatherResults(
            [defer.maybeDeferred(db.requestAvatarId, c) for c in creds])
        d.addCallback(self.assertEquals, [u for u, p in self.users])
        return d

Example 6

Project: mythbox Source File: test_newcred.py
Function: set_up
    def setUp(self):
        dbfile = self.mktemp()
        self.db = checkers.FilePasswordDB(dbfile, hash=self.hash)
        f = file(dbfile, 'w')
        for (u, p) in self.users:
            f.write('%s:%s\n' % (u, crypt(p, u[:2])))
        f.close()
        r = TestRealm()
        self.port = portal.Portal(r)
        self.port.registerChecker(self.db)

Example 7

Project: mythbox Source File: test_strcred.py
Function: set_up
    def setUp(self):
        self.filename = self.mktemp()
        file(self.filename, 'w').write('admin:asdf\nalice:foo\n')
        self.goodChecker = checkers.FilePasswordDB(self.filename)
        self.badChecker = checkers.FilePasswordDB(self.filename, hash=self._hash)
        self.anonChecker = checkers.AllowAnonymousAccess()

Example 8

Project: vcdm Source File: daemon.py
def load_authn_conf():
    _used_checkers = []
    _authn_methods = []
    if conf.has_option('general', 'usersdb.plaintext'):
        print "Using plaintext users DB from '%s'" % conf.get('general', 'usersdb.plaintext')
        _used_checkers.append(FilePasswordDB(conf.get('general', 'usersdb.plaintext'),
                                            cache=True))
        _authn_methods.append(guard.DigestCredentialFactory('md5',
                                            conf.get('general', 'server.endpoint')))
    elif conf.has_option('general', 'usersdb.md5'):
        print "Using md5-hashed users DB from '%s'" % conf.get('general', 'usersdb.md5')
        _used_checkers.append(FilePasswordDB(conf.get('general', 'usersdb.md5'),
                                                       hash=_hash, cache=True))
        _authn_methods.append(guard.BasicCredentialFactory(conf.get('general', 'server.endpoint')))
    _used_checkers.append(AllowAnonymousAccess())
    vcdm.env['authn_methods'] = (_authn_methods, _used_checkers)

Example 9

Project: SubliminalCollaborator Source File: ftp.py
    def opt_password_file(self, filename):
        """
        Specify a file containing username:password login info for
        authenticated connections. (DEPRECATED; see --help-auth instead)
        """
        self['password-file'] = filename
        msg = deprecate.getDeprecationWarningString(
            self.opt_password_file, versions.Version('Twisted', 11, 1, 0))
        warnings.warn(msg, category=DeprecationWarning, stacklevel=2)
        self.addChecker(checkers.FilePasswordDB(filename, cache=True))

Example 10

Project: SubliminalCollaborator Source File: test_newcred.py
Function: test_user_lookup
    def testUserLookup(self):
        dbfile = self.mktemp()
        db = checkers.FilePasswordDB(dbfile)
        f = file(dbfile, 'w')
        for (u, p) in self.users:
            f.write('%s:%s\n' % (u, p))
        f.close()

        for (u, p) in self.users:
            self.failUnlessRaises(KeyError, db.getUser, u.upper())
            self.assertEqual(db.getUser(u), (u, p))

Example 11

Project: SubliminalCollaborator Source File: test_newcred.py
Function: test_case_insensitivity
    def testCaseInSensitivity(self):
        dbfile = self.mktemp()
        db = checkers.FilePasswordDB(dbfile, caseSensitive=0)
        f = file(dbfile, 'w')
        for (u, p) in self.users:
            f.write('%s:%s\n' % (u, p))
        f.close()

        for (u, p) in self.users:
            self.assertEqual(db.getUser(u.upper()), (u, p))

Example 12

Project: SubliminalCollaborator Source File: test_newcred.py
Function: test_request_avatar_id
    def testRequestAvatarId(self):
        dbfile = self.mktemp()
        db = checkers.FilePasswordDB(dbfile, caseSensitive=0)
        f = file(dbfile, 'w')
        for (u, p) in self.users:
            f.write('%s:%s\n' % (u, p))
        f.close()
        creds = [credentials.UsernamePassword(u, p) for u, p in self.users]
        d = defer.gatherResults(
            [defer.maybeDeferred(db.requestAvatarId, c) for c in creds])
        d.addCallback(self.assertEqual, [u for u, p in self.users])
        return d

Example 13

Project: SubliminalCollaborator Source File: test_newcred.py
Function: testrequestavatarid_hashed
    def testRequestAvatarId_hashed(self):
        dbfile = self.mktemp()
        db = checkers.FilePasswordDB(dbfile, caseSensitive=0)
        f = file(dbfile, 'w')
        for (u, p) in self.users:
            f.write('%s:%s\n' % (u, p))
        f.close()
        creds = [credentials.UsernameHashedPassword(u, p) for u, p in self.users]
        d = defer.gatherResults(
            [defer.maybeDeferred(db.requestAvatarId, c) for c in creds])
        d.addCallback(self.assertEqual, [u for u, p in self.users])
        return d

Example 14

Project: SubliminalCollaborator Source File: test_strcred.py
Function: set_up
    def setUp(self):
        self.filename = self.mktemp()
        file(self.filename, 'w').write('admin:asdf\nalice:foo\n')
        self.goodChecker = checkers.FilePasswordDB(self.filename)
        self.badChecker = checkers.FilePasswordDB(
            self.filename, hash=self._hash)
        self.anonChecker = checkers.AllowAnonymousAccess()

Example 15

Project: SubliminalCollaborator Source File: tap.py
    def opt_passwd(self, filename):
        """
        Name of a passwd-style file. (This is for
        backwards-compatibility only; you should use the --auth
        command instead.)
        """
        self.addChecker(checkers.FilePasswordDB(filename))

Example 16

Project: mythbox Source File: manhole_tap.py
def makeService(options):
    """Create a manhole server service.

    @type options: C{dict}
    @param options: A mapping describing the configuration of
    the desired service.  Recognized key/value pairs are::

        "telnetPort": strports description of the address on which
                      to listen for telnet connections.  If None,
                      no telnet service will be started.

        "sshPort": strports description of the address on which to
                   listen for ssh connections.  If None, no ssh
                   service will be started.

        "namespace": dictionary containing desired initial locals
                     for manhole connections.  If None, an empty
                     dictionary will be used.

        "passwd": Name of a passwd(5)-format username/password file.

    @rtype: L{twisted.application.service.IService}
    @return: A manhole service.
    """

    svc = service.MultiService()

    namespace = options['namespace']
    if namespace is None:
        namespace = {}

    checker = checkers.FilePasswordDB(options['passwd'])

    if options['telnetPort']:
        telnetRealm = _StupidRealm(telnet.TelnetBootstrapProtocol,
                                   insults.ServerProtocol,
                                   manhole.ColoredManhole,
                                   namespace)

        telnetPortal = portal.Portal(telnetRealm, [checker])

        telnetFactory = protocol.ServerFactory()
        telnetFactory.protocol = makeTelnetProtocol(telnetPortal)
        telnetService = strports.service(options['telnetPort'],
                                         telnetFactory)
        telnetService.setServiceParent(svc)

    if options['sshPort']:
        sshRealm = manhole_ssh.TerminalRealm()
        sshRealm.chainedProtocolFactory = chainedProtocolFactory(namespace)

        sshPortal = portal.Portal(sshRealm, [checker])
        sshFactory = manhole_ssh.ConchFactory(sshPortal)
        sshService = strports.service(options['sshPort'],
                                      sshFactory)
        sshService.setServiceParent(svc)

    return svc

Example 17

Project: mythbox Source File: test_newcred.py
    def getCheckers(self):
        diskHash = self.diskHash or (lambda x: x)
        hashCheck = self.diskHash and (lambda username, password, stored: self.diskHash(password))

        for cache in True, False:
            fn = self.mktemp()
            fObj = file(fn, 'w')
            for u, p in self._validCredentials:
                fObj.write('%s:%s\n' % (u, diskHash(p)))
            fObj.close()
            yield checkers.FilePasswordDB(fn, cache=cache, hash=hashCheck)

            fn = self.mktemp()
            fObj = file(fn, 'w')
            for u, p in self._validCredentials:
                fObj.write('%s dingle dongle %s\n' % (diskHash(p), u))
            fObj.close()
            yield checkers.FilePasswordDB(fn, ' ', 3, 0, cache=cache, hash=hashCheck)

            fn = self.mktemp()
            fObj = file(fn, 'w')
            for u, p in self._validCredentials:
                fObj.write('zip,zap,%s,zup,%s\n' % (u.title(), diskHash(p)))
            fObj.close()
            yield checkers.FilePasswordDB(fn, ',', 2, 4, False, cache=cache, hash=hashCheck)