1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22 """
23 Flumotion Twisted credential checkers
24 """
25
26 from twisted.cred import checkers, error
27 from twisted.internet import defer
28 from twisted.python import failure
29
30 from flumotion.common import log
31 from flumotion.twisted import credentials
32 from flumotion.twisted.compat import implements
33
34
35
36 parent = checkers.InMemoryUsernamePasswordDatabaseDontUse
38 """
39 I am an in-memory username/password credentials checker that also
40 allows anonymous logins if instructed to do so.
41 """
42 logCategory = 'credchecker'
44 parent.__init__(self, **users)
45 self._passwordless = False
46
48 self._passwordless = wellDoWeQuestionMark
49
50
65
73
75 """
76 I check credentials using a crypt-based backend.
77 """
78 implements(checkers.ICredentialsChecker)
79 credentialInterfaces = (credentials.IUsernameCryptPassword, )
80
81 logCategory = 'cryptchecker'
82
85
86 - def addUser(self, username, cryptPassword):
87 """
88 Add the given username and password.
89
90 @param username: name of the user to add
91 @type username: string
92 @param cryptPassword: the crypted password for this user
93 @type cryptPassword: string
94 """
95 self.debug('added user %s' % username)
96 self.users[username] = cryptPassword
97
99 if matched:
100 self.debug('user %s authenticated' % username)
101 return username
102 else:
103 self.debug('user %s refused, password not matched' % username)
104 return failure.Failure(error.UnauthorizedLogin())
105
106
117
119 """
120 I check credentials using a SHA-256-based backend.
121 """
122 implements(checkers.ICredentialsChecker)
123 credentialInterfaces = (credentials.IUsernameSha256Password, )
124
125 logCategory = 'sha256checker'
126
129
130 - def addUser(self, username, salt, sha256Data):
131 """
132 Add the given username and password.
133
134 @param username: name of the user to add
135 @type username: str
136 @param salt: the salt for this user
137 @type salt: str
138 @param sha256Data: the sha256 data for this user
139 @type sha256Data: str
140 """
141 self.debug('added user %s' % username)
142 self.users[username] = (salt, sha256Data)
143
145 if matched:
146 self.debug('user %s authenticated' % username)
147 return username
148 else:
149 self.debug('user %s refused, password not matched' % username)
150 return failure.Failure(error.UnauthorizedLogin())
151
152
165