Mercurial > p > roundup > code
comparison roundup/password.py @ 302:d1fb3fcdb11b
Catch errors in login - no username or password supplied.
Fixed editing of password (Password property type) thanks Roch'e Compaan.
| author | Richard Jones <richard@users.sourceforge.net> |
|---|---|
| date | Sat, 20 Oct 2001 11:58:48 +0000 |
| parents | 1cc866cec608 |
| children | bdc2ea127ae9 |
comparison
equal
deleted
inserted
replaced
| 301:7901b58cfae8 | 302:d1fb3fcdb11b |
|---|---|
| 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS | 13 # BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS |
| 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" | 14 # FOR A PARTICULAR PURPOSE. THE CODE PROVIDED HEREUNDER IS ON AN "AS IS" |
| 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, | 15 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE, |
| 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. | 16 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS. |
| 17 # | 17 # |
| 18 # $Id: password.py,v 1.2 2001-10-09 23:58:10 richard Exp $ | 18 # $Id: password.py,v 1.3 2001-10-20 11:58:48 richard Exp $ |
| 19 | 19 |
| 20 import sha, re | 20 import sha, re |
| 21 | 21 |
| 22 def encodePassword(plaintext, scheme): | 22 def encodePassword(plaintext, scheme): |
| 23 '''Encrypt the plaintext password. | 23 '''Encrypt the plaintext password. |
| 80 | 80 |
| 81 def setPassword(self, plaintext): | 81 def setPassword(self, plaintext): |
| 82 '''Sets encrypts plaintext.''' | 82 '''Sets encrypts plaintext.''' |
| 83 self.password = encodePassword(plaintext, self.scheme) | 83 self.password = encodePassword(plaintext, self.scheme) |
| 84 | 84 |
| 85 def __cmp__(self, plaintext): | 85 def __cmp__(self, other): |
| 86 '''Compare this password against the plaintext.''' | 86 '''Compare this password against another password.''' |
| 87 # check to see if we're comparing instances | |
| 88 if isinstance(other, Password): | |
| 89 if self.scheme != other.scheme: | |
| 90 return | |
| 91 return cmp(self.password, other.password) | |
| 92 | |
| 93 # assume password is plaintext | |
| 87 if self.password is None: | 94 if self.password is None: |
| 88 raise ValueError, 'Password not set' | 95 raise ValueError, 'Password not set' |
| 89 return cmp(self.password, encodePassword(plaintext, self.scheme)) | 96 return cmp(self.password, encodePassword(other, self.scheme)) |
| 90 | 97 |
| 91 def __str__(self): | 98 def __str__(self): |
| 92 '''Stringify the encrypted password for database storage.''' | 99 '''Stringify the encrypted password for database storage.''' |
| 93 if self.password is None: | 100 if self.password is None: |
| 94 raise ValueError, 'Password not set' | 101 raise ValueError, 'Password not set' |
| 104 if __name__ == '__main__': | 111 if __name__ == '__main__': |
| 105 test() | 112 test() |
| 106 | 113 |
| 107 # | 114 # |
| 108 # $Log: not supported by cvs2svn $ | 115 # $Log: not supported by cvs2svn $ |
| 116 # Revision 1.2 2001/10/09 23:58:10 richard | |
| 117 # Moved the data stringification up into the hyperdb.Class class' get, set | |
| 118 # and create methods. This means that the data is also stringified for the | |
| 119 # journal call, and removes duplication of code from the backends. The | |
| 120 # backend code now only sees strings. | |
| 121 # | |
| 109 # Revision 1.1 2001/10/09 07:25:59 richard | 122 # Revision 1.1 2001/10/09 07:25:59 richard |
| 110 # Added the Password property type. See "pydoc roundup.password" for | 123 # Added the Password property type. See "pydoc roundup.password" for |
| 111 # implementation details. Have updated some of the documentation too. | 124 # implementation details. Have updated some of the documentation too. |
| 112 # | 125 # |
| 113 # | 126 # |
