fixed CRYPT

This commit is contained in:
mdipierro
2012-07-20 08:58:13 -05:00
parent 37055d7e08
commit 6903db9d7c
4 changed files with 29 additions and 9 deletions
+1 -1
View File
@@ -1 +1 @@
Version 2.00.0 (2012-07-19 16:56:40) dev
Version 2.00.0 (2012-07-20 08:58:08) dev
+2 -1
View File
@@ -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 '')
+6 -6
View File
@@ -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'):
+20 -1
View File
@@ -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,