diff --git a/roundup/password.py b/roundup/password.py
index 0ba2c5e39f3c7d3b37ffa83c95297e27d2679907..97de75d08be5cd4a4d2ca7dfbd9eaedb726c4f73 100644 (file)
--- a/roundup/password.py
+++ b/roundup/password.py
# BASIS, AND THERE IS NO OBLIGATION WHATSOEVER TO PROVIDE MAINTENANCE,
# SUPPORT, UPDATES, ENHANCEMENTS, OR MODIFICATIONS.
#
-# $Id: password.py,v 1.6 2002-09-26 07:39:21 richard Exp $
+# $Id: password.py,v 1.10 2003-11-11 00:35:13 richard Exp $
__doc__ = """
Password handling (encoding, decoding).
"""
-import sha, re, string
+import sha, re, string, random
try:
- import crypt:
+ import crypt
except:
crypt = None
pass
+class PasswordValueError(ValueError):
+ ''' The password value is not valid '''
+ pass
+
def encodePassword(plaintext, scheme, other=None):
'''Encrypt the plaintext password.
'''
+ if plaintext is None:
+ plaintext = ""
if scheme == 'SHA':
s = sha.sha(plaintext).hexdigest()
elif scheme == 'crypt' and crypt is not None:
elif scheme == 'plaintext':
s = plaintext
else:
- raise ValueError, 'Unknown encryption scheme "%s"'%scheme
+ raise PasswordValueError, 'unknown encryption scheme %r'%scheme
return s
+def generatePassword(length=8):
+ chars = string.letters+string.digits
+ return ''.join([random.choice(chars) for x in range(length)])
+
class Password:
'''The class encapsulates a Password property type value in the database.