diff roundup/password.py @ 2277:c9e52addda42

added MD5 scheme for password hiding
author Richard Jones <richard@users.sourceforge.net>
date Mon, 10 May 2004 22:32:17 +0000
parents 18addf2a8596
children 1f860b50fa5f
line wrap: on
line diff
--- a/roundup/password.py	Mon May 10 01:30:02 2004 +0000
+++ b/roundup/password.py	Mon May 10 22:32:17 2004 +0000
@@ -15,13 +15,13 @@
 # BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
 # SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
 # 
-# $Id: password.py,v 1.12 2004-03-22 07:45:39 richard Exp $
+# $Id: password.py,v 1.13 2004-05-10 22:32:17 richard Exp $
 
 """Password handling (encoding, decoding).
 """
 __docformat__ = 'restructuredtext'
 
-import sha, re, string, random
+import sha, md5, re, string, random
 try:
     import crypt
 except:
@@ -39,6 +39,8 @@
         plaintext = ""
     if scheme == 'SHA':
         s = sha.sha(plaintext).hexdigest()
+    elif scheme == 'MD5':
+        s = md5.md5(plaintext).hexdigest()
     elif scheme == 'crypt' and crypt is not None:
         if other is not None:
             salt = other[:2]
@@ -59,8 +61,8 @@
 class Password:
     '''The class encapsulates a Password property type value in the database. 
 
-    The encoding of the password is one if None, 'SHA' or 'plaintext'. The
-    encodePassword function is used to actually encode the password from
+    The encoding of the password is one if None, 'SHA', 'MD5' or 'plaintext'.
+    The encodePassword function is used to actually encode the password from
     plaintext. The None encoding is used in legacy databases where no
     encoding scheme is identified.
 
@@ -142,6 +144,13 @@
     assert 'sekrit' == p
     assert 'not sekrit' != p
 
+    # MD5
+    p = Password('sekrit', 'MD5')
+    assert p == 'sekrit'
+    assert p != 'not sekrit'
+    assert 'sekrit' == p
+    assert 'not sekrit' != p
+
     # crypt
     p = Password('sekrit', 'crypt')
     assert p == 'sekrit'

Roundup Issue Tracker: http://roundup-tracker.org/