Mercurial > p > roundup > code
annotate roundup/password.py @ 2077:3e0961d6d44d
Added the "actor" property.
Metakit backend not done (still not confident I know how it's supposed
to work ;)
Currently it will come up as NULL in the RDBMS backends for older items.
The *dbm backends will look up the journal. I hope to remedy the former
before 0.7's release.
Fixed a bunch of migration issues in the rdbms backends while I was at it
(index changes for key prop changes) and simplified the class table update
code for RDBMSes that have "alter table" in their command set (ie. not
sqlite) ... migration from "version 1" to "version 2" still hasn't
actually been tested yet though.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Mon, 15 Mar 2004 05:50:20 +0000 |
| parents | fc52d57c6c3e |
| children | 18addf2a8596 |
| rev | line source |
|---|---|
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
1 # |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
2 # Copyright (c) 2001 Bizar Software Pty Ltd (http://www.bizarsoftware.com.au/) |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
3 # This module is free software, and you may redistribute it and/or modify |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
4 # under the same terms as Python, so long as this copyright message and |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
5 # disclaimer are retained in their original form. |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
6 # |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
7 # IN NO EVENT SHALL BIZAR SOFTWARE PTY LTD BE LIABLE TO ANY PARTY FOR |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
8 # DIRECT, INDIRECT, SPECIAL, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
9 # OUT OF THE USE OF THIS CODE, EVEN IF THE AUTHOR HAS BEEN ADVISED OF THE |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
10 # POSSIBILITY OF SUCH DAMAGE. |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
11 # |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
12 # BIZAR SOFTWARE PTY LTD SPECIFICALLY DISCLAIMS ANY WARRANTIES, INCLUDING, |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
17 # |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1905
diff
changeset
|
18 # $Id: password.py,v 1.11 2004-02-11 23:55:08 richard Exp $ |
|
406
bdc2ea127ae9
Added module docstrings to all modules.
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
302
diff
changeset
|
19 |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1905
diff
changeset
|
20 """Password handling (encoding, decoding). |
|
406
bdc2ea127ae9
Added module docstrings to all modules.
Jürgen Hermann <jhermann@users.sourceforge.net>
parents:
302
diff
changeset
|
21 """ |
|
2005
fc52d57c6c3e
documentation cleanup
Richard Jones <richard@users.sourceforge.net>
parents:
1905
diff
changeset
|
22 __docformat__ = 'restructuredtext' |
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
23 |
|
1583
caae7d8934dc
set new email rego user password to random string
Richard Jones <richard@users.sourceforge.net>
parents:
1343
diff
changeset
|
24 import sha, re, string, random |
|
1229
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
25 try: |
| 1231 | 26 import crypt |
|
1229
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
27 except: |
|
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
28 crypt = None |
|
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
29 pass |
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
30 |
|
1905
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1583
diff
changeset
|
31 class PasswordValueError(ValueError): |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1583
diff
changeset
|
32 ''' The password value is not valid ''' |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1583
diff
changeset
|
33 pass |
|
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1583
diff
changeset
|
34 |
|
1229
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
35 def encodePassword(plaintext, scheme, other=None): |
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
36 '''Encrypt the plaintext password. |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
37 ''' |
|
1343
2e557762ee87
fixed handling of missing password [SF#655632]
Richard Jones <richard@users.sourceforge.net>
parents:
1231
diff
changeset
|
38 if plaintext is None: |
|
2e557762ee87
fixed handling of missing password [SF#655632]
Richard Jones <richard@users.sourceforge.net>
parents:
1231
diff
changeset
|
39 plaintext = "" |
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
40 if scheme == 'SHA': |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
41 s = sha.sha(plaintext).hexdigest() |
|
1229
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
42 elif scheme == 'crypt' and crypt is not None: |
|
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
43 if other is not None: |
|
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
44 salt = other[:2] |
|
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
45 else: |
|
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
46 saltchars = './0123456789'+string.letters |
|
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
47 salt = random.choice(saltchars) + random.choice(saltchars) |
|
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
48 s = crypt.crypt(plaintext, salt) |
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
49 elif scheme == 'plaintext': |
|
1229
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
50 s = plaintext |
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
51 else: |
|
1905
dc43e339e607
Centralised conversion of user-input data to hyperdb values
Richard Jones <richard@users.sourceforge.net>
parents:
1583
diff
changeset
|
52 raise PasswordValueError, 'unknown encryption scheme %r'%scheme |
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
53 return s |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
54 |
|
1583
caae7d8934dc
set new email rego user password to random string
Richard Jones <richard@users.sourceforge.net>
parents:
1343
diff
changeset
|
55 def generatePassword(length=8): |
|
caae7d8934dc
set new email rego user password to random string
Richard Jones <richard@users.sourceforge.net>
parents:
1343
diff
changeset
|
56 chars = string.letters+string.digits |
|
caae7d8934dc
set new email rego user password to random string
Richard Jones <richard@users.sourceforge.net>
parents:
1343
diff
changeset
|
57 return ''.join([random.choice(chars) for x in range(length)]) |
|
caae7d8934dc
set new email rego user password to random string
Richard Jones <richard@users.sourceforge.net>
parents:
1343
diff
changeset
|
58 |
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
59 class Password: |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
60 '''The class encapsulates a Password property type value in the database. |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
61 |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
62 The encoding of the password is one if None, 'SHA' or 'plaintext'. The |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
63 encodePassword function is used to actually encode the password from |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
64 plaintext. The None encoding is used in legacy databases where no |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
65 encoding scheme is identified. |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
66 |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
67 The scheme is stored with the encoded data in the database: |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
68 {scheme}data |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
69 |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
70 Example usage: |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
71 >>> p = Password('sekrit') |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
72 >>> p == 'sekrit' |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
73 1 |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
74 >>> p != 'not sekrit' |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
75 1 |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
76 >>> 'sekrit' == p |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
77 1 |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
78 >>> 'not sekrit' != p |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
79 1 |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
80 ''' |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
81 |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
82 default_scheme = 'SHA' # new encryptions use this scheme |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
83 pwre = re.compile(r'{(\w+)}(.+)') |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
84 |
|
1229
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
85 def __init__(self, plaintext=None, scheme=None): |
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
86 '''Call setPassword if plaintext is not None.''' |
|
1229
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
87 if scheme is None: |
|
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
88 scheme = self.default_scheme |
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
89 if plaintext is not None: |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
90 self.password = encodePassword(plaintext, self.default_scheme) |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
91 self.scheme = self.default_scheme |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
92 else: |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
93 self.password = None |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
94 self.scheme = self.default_scheme |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
95 |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
96 def unpack(self, encrypted): |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
97 '''Set the password info from the scheme:<encryted info> string |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
98 (the inverse of __str__) |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
99 ''' |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
100 m = self.pwre.match(encrypted) |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
101 if m: |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
102 self.scheme = m.group(1) |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
103 self.password = m.group(2) |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
104 else: |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
105 # currently plaintext - encrypt |
|
275
1cc866cec608
Moved the data stringification up into the hyperdb.Class class's...
Richard Jones <richard@users.sourceforge.net>
parents:
270
diff
changeset
|
106 self.password = encodePassword(encrypted, self.default_scheme) |
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
107 self.scheme = self.default_scheme |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
108 |
|
1229
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
109 def setPassword(self, plaintext, scheme=None): |
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
110 '''Sets encrypts plaintext.''' |
|
1229
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
111 if scheme is None: |
|
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
112 scheme = self.default_scheme |
|
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
113 self.password = encodePassword(plaintext, scheme) |
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
114 |
|
302
d1fb3fcdb11b
Catch errors in login - no username or password supplied.
Richard Jones <richard@users.sourceforge.net>
parents:
275
diff
changeset
|
115 def __cmp__(self, other): |
|
d1fb3fcdb11b
Catch errors in login - no username or password supplied.
Richard Jones <richard@users.sourceforge.net>
parents:
275
diff
changeset
|
116 '''Compare this password against another password.''' |
|
d1fb3fcdb11b
Catch errors in login - no username or password supplied.
Richard Jones <richard@users.sourceforge.net>
parents:
275
diff
changeset
|
117 # check to see if we're comparing instances |
|
d1fb3fcdb11b
Catch errors in login - no username or password supplied.
Richard Jones <richard@users.sourceforge.net>
parents:
275
diff
changeset
|
118 if isinstance(other, Password): |
|
d1fb3fcdb11b
Catch errors in login - no username or password supplied.
Richard Jones <richard@users.sourceforge.net>
parents:
275
diff
changeset
|
119 if self.scheme != other.scheme: |
|
1229
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
120 return cmp(self.scheme, other.scheme) |
|
302
d1fb3fcdb11b
Catch errors in login - no username or password supplied.
Richard Jones <richard@users.sourceforge.net>
parents:
275
diff
changeset
|
121 return cmp(self.password, other.password) |
|
d1fb3fcdb11b
Catch errors in login - no username or password supplied.
Richard Jones <richard@users.sourceforge.net>
parents:
275
diff
changeset
|
122 |
|
d1fb3fcdb11b
Catch errors in login - no username or password supplied.
Richard Jones <richard@users.sourceforge.net>
parents:
275
diff
changeset
|
123 # assume password is plaintext |
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
124 if self.password is None: |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
125 raise ValueError, 'Password not set' |
|
1229
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
126 return cmp(self.password, encodePassword(other, self.scheme, |
|
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
127 self.password)) |
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
128 |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
129 def __str__(self): |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
130 '''Stringify the encrypted password for database storage.''' |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
131 if self.password is None: |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
132 raise ValueError, 'Password not set' |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
133 return '{%s}%s'%(self.scheme, self.password) |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
134 |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
135 def test(): |
|
1229
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
136 # SHA |
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
137 p = Password('sekrit') |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
138 assert p == 'sekrit' |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
139 assert p != 'not sekrit' |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
140 assert 'sekrit' == p |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
141 assert 'not sekrit' != p |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
142 |
|
1229
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
143 # crypt |
|
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
144 p = Password('sekrit', 'crypt') |
|
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
145 assert p == 'sekrit' |
|
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
146 assert p != 'not sekrit' |
|
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
147 assert 'sekrit' == p |
|
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
148 assert 'not sekrit' != p |
|
5c581b120738
added "crypt" password encoding...
Richard Jones <richard@users.sourceforge.net>
parents:
1090
diff
changeset
|
149 |
|
270
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
150 if __name__ == '__main__': |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
151 test() |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
152 |
|
a4241ddd22d7
Added the Password property type.
Richard Jones <richard@users.sourceforge.net>
parents:
diff
changeset
|
153 # vim: set filetype=python ts=4 sw=4 et si |
