* use "hashlib" instead of "sha" (deprecated since python2.6) if available

This commit is contained in:
lars 2009-06-16 02:16:29 +00:00
parent d5dce0887a
commit 8e9f5eedc2

View file

@ -443,7 +443,15 @@ class CryptoBoxSettings:
def __get_user_db(self):
"""Load the user database file if it exists.
"""
import StringIO, sha
import StringIO
try:
# hashlib is available since python2.5
import hashlib
get_hash_obj = lambda text: hashlib.sha1(text)
except ImportError:
# sha is deprecated since python2.6
import sha
get_hash_obj = lambda text: sha.new(text)
user_db_rules = StringIO.StringIO(self.userDatabaseSpec)
try:
try:
@ -468,7 +476,7 @@ class CryptoBoxSettings:
## validate and set default value for "admin" user
user_db.validate(validate.Validator())
## define password hash function - never use "sha" directly - SPOT
user_db.get_digest = lambda password: sha.new(password).hexdigest()
user_db.get_digest = lambda password: get_hash_obj(password).hexdigest()
return user_db