From 6903db9d7c2535375e6802294adeb56f5c71f785 Mon Sep 17 00:00:00 2001 From: mdipierro Date: Fri, 20 Jul 2012 08:58:13 -0500 Subject: [PATCH] fixed CRYPT --- VERSION | 2 +- gluon/tools.py | 3 ++- gluon/utils.py | 12 ++++++------ gluon/validators.py | 21 ++++++++++++++++++++- 4 files changed, 29 insertions(+), 9 deletions(-) diff --git a/VERSION b/VERSION index d44d196a..33097687 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.00.0 (2012-07-19 16:56:40) dev +Version 2.00.0 (2012-07-20 08:58:08) dev diff --git a/gluon/tools.py b/gluon/tools.py index 4eaafd8e..0dd4c58c 100644 --- a/gluon/tools.py +++ b/gluon/tools.py @@ -1198,7 +1198,8 @@ class Auth(object): if URL() == action: next = '' else: - next = '?_next=' + urllib.quote(URL(args=request.args, vars=request.get_vars)) + next = '?_next=' + urllib.quote(URL(args=request.args, + vars=request.get_vars)) href = lambda function: '%s/%s%s' % (action, function, next if referrer_actions is DEFAULT or function in referrer_actions else '') diff --git a/gluon/utils.py b/gluon/utils.py index 64a714ab..3c68ab85 100644 --- a/gluon/utils.py +++ b/gluon/utils.py @@ -72,12 +72,12 @@ def get_digest(value): raise ValueError("Invalid digest algorithm") DIGEST_ALG_BY_SIZE = { - 128/16: 'md5', - 160/16: 'sha1', - 224/16: 'sha224', - 256/16: 'sha256', - 384/16: 'sha384', - 512/16: 'sha512', + 128/4: 'md5', + 160/4: 'sha1', + 224/4: 'sha224', + 256/4: 'sha256', + 384/4: 'sha384', + 512/4: 'sha512', } def hmac_hash(value, salt, digest_alg='md5'): diff --git a/gluon/validators.py b/gluon/validators.py index 85d23539..a5fab8cb 100644 --- a/gluon/validators.py +++ b/gluon/validators.py @@ -2579,7 +2579,13 @@ class LazyCrypt(object): """ compares the current lazy crypted password with a stored password """ - key = self.crypt.key.split(':')[1] if ':' in self.crypt.key else '' + if self.crypt.key: + if ':' in self.crypt.key: + key = self.crypt.key.split(':')[1] + else: + key = self.crypt.key + else: + key = '' if stored_password.count('$')==2: (digest_alg, salt, hash) = stored_password.split('$') masterkey = key+salt @@ -2629,6 +2635,19 @@ class CRYPT(object): Important: hashed password is returned as a LazyCrypt object and computed only if needed. The LasyCrypt object also knows how to compare itself with an existing salted password + Some tests: + + >>> a = str(CRYPT(digest_alg='sha1',salt=False)('test')[0]) + >>> a + 'sha1$$a94a8fe5ccb19ba61c4c0873d391e987982fbbd3' + >>> CRYPT(digest_alg='sha1',salt=False)('test')[0] == a + True + >>> CRYPT(digest_alg='sha1',salt=False)('test')[0] == a[6:] + True + >>> CRYPT(digest_alg='md5',salt=False)('test')[0] == a + True + >>> CRYPT(digest_alg='md5',salt=False)('test')[0] == a[6:] + True """ def __init__(self,