diff --git a/VERSION b/VERSION index 32854ec6..c81af7c3 100644 --- a/VERSION +++ b/VERSION @@ -1 +1 @@ -Version 2.10.0-trunk+timestamp.2014.08.10.12.07.07 +Version 2.10.0-trunk+timestamp.2014.08.10.12.45.17 diff --git a/gluon/utils.py b/gluon/utils.py index c4d57bc6..e5b481b9 100644 --- a/gluon/utils.py +++ b/gluon/utils.py @@ -34,6 +34,7 @@ if python_version == 2: else: import pickle +import hashlib from hashlib import md5, sha1, sha224, sha256, sha384, sha512 try: @@ -43,18 +44,26 @@ except ImportError: import hmac -try: - try: - from gluon.contrib.pbkdf2_ctypes import pbkdf2_hex - except (ImportError, AttributeError): - from gluon.contrib.pbkdf2 import pbkdf2_hex +if hasattr(hashlib, "pbkdf2_hmac"): + def pbkdf2_hex(data, salt, iterations=1000, keylen=24, hashfunc=None): + hashfunc = hashfunc or sha1 + return hashlib.pbkdf2_hmac(hashfunc().name, + data, salt, iterations, + keylen).encode("hex") HAVE_PBKDF2 = True -except ImportError: +else: try: - from .pbkdf2 import pbkdf2_hex + try: + from gluon.contrib.pbkdf2_ctypes import pbkdf2_hex + except (ImportError, AttributeError): + from gluon.contrib.pbkdf2 import pbkdf2_hex HAVE_PBKDF2 = True - except (ImportError, ValueError): - HAVE_PBKDF2 = False + except ImportError: + try: + from .pbkdf2 import pbkdf2_hex + HAVE_PBKDF2 = True + except (ImportError, ValueError): + HAVE_PBKDF2 = False logger = logging.getLogger("web2py")