Code

import fixes
[roundup.git] / roundup / password.py
index cc76c31b7edb0c6b00834bc2911bba5c740cac7c..1caa8a83438c2cc8506078d48ddf78dcee5b293e 100644 (file)
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: password.py,v 1.1 2001-10-09 07:25:59 richard Exp $
+# $Id: password.py,v 1.5 2002-09-10 00:18:20 richard Exp $
+
+__doc__ = """
+Password handling (encoding, decoding).
+"""
 
 import sha, re
 
@@ -75,18 +79,25 @@ class Password:
             self.password = m.group(2)
         else:
             # currently plaintext - encrypt
-            self.password = encodePassword(plaintext, self.default_scheme)
+            self.password = encodePassword(encrypted, self.default_scheme)
             self.scheme = self.default_scheme
 
     def setPassword(self, plaintext):
         '''Sets encrypts plaintext.'''
         self.password = encodePassword(plaintext, self.scheme)
 
-    def __cmp__(self, plaintext):
-        '''Compare this password against the plaintext.'''
+    def __cmp__(self, other):
+        '''Compare this password against another password.'''
+        # check to see if we're comparing instances
+        if isinstance(other, Password):
+            if self.scheme != other.scheme:
+                return
+            return cmp(self.password, other.password)
+
+        # assume password is plaintext
         if self.password is None:
             raise ValueError, 'Password not set'
-        return cmp(self.password, encodePassword(plaintext, self.scheme))
+        return cmp(self.password, encodePassword(other, self.scheme))
 
     def __str__(self):
         '''Stringify the encrypted password for database storage.'''
@@ -104,8 +115,4 @@ def test():
 if __name__ == '__main__':
     test()
 
-#
-# $Log: not supported by cvs2svn $
-#
-#
 # vim: set filetype=python ts=4 sw=4 et si