1515# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
1616# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
1717#
18- # $Id: password.py,v 1.12 2004-03-22 07:45:39 richard Exp $
18+ # $Id: password.py,v 1.13 2004-05-10 22:32:17 richard Exp $
1919
2020"""Password handling (encoding, decoding).
2121"""
2222__docformat__ = 'restructuredtext'
2323
24- import sha , re , string , random
24+ import sha , md5 , re , string , random
2525try :
2626 import crypt
2727except :
@@ -39,6 +39,8 @@ def encodePassword(plaintext, scheme, other=None):
3939 plaintext = ""
4040 if scheme == 'SHA' :
4141 s = sha .sha (plaintext ).hexdigest ()
42+ elif scheme == 'MD5' :
43+ s = md5 .md5 (plaintext ).hexdigest ()
4244 elif scheme == 'crypt' and crypt is not None :
4345 if other is not None :
4446 salt = other [:2 ]
@@ -59,8 +61,8 @@ def generatePassword(length=8):
5961class Password :
6062 '''The class encapsulates a Password property type value in the database.
6163
62- The encoding of the password is one if None, 'SHA' or 'plaintext'. The
63- encodePassword function is used to actually encode the password from
64+ The encoding of the password is one if None, 'SHA', 'MD5' or 'plaintext'.
65+ The encodePassword function is used to actually encode the password from
6466 plaintext. The None encoding is used in legacy databases where no
6567 encoding scheme is identified.
6668
@@ -142,6 +144,13 @@ def test():
142144 assert 'sekrit' == p
143145 assert 'not sekrit' != p
144146
147+ # MD5
148+ p = Password ('sekrit' , 'MD5' )
149+ assert p == 'sekrit'
150+ assert p != 'not sekrit'
151+ assert 'sekrit' == p
152+ assert 'not sekrit' != p
153+
145154 # crypt
146155 p = Password ('sekrit' , 'crypt' )
147156 assert p == 'sekrit'
0 commit comments