mirror of
https://github.com/django/django.git
synced 2025-07-04 01:39:20 +00:00
Use the stdlib's PBKDF2 implementation when available.
This is a bit faster than ours, which is good, because it lets you increase the iteration counts. This will be used on Python 3.4+, and, pending the acceptance of PEP466, on newer Python 2.7s.
This commit is contained in:
parent
47927eb786
commit
cb68eb3e6d
@ -15,9 +15,10 @@ class ExpressionNode(tree.Node):
|
|||||||
MUL = '*'
|
MUL = '*'
|
||||||
DIV = '/'
|
DIV = '/'
|
||||||
POW = '^'
|
POW = '^'
|
||||||
MOD = '%%' # This is a quoted % operator - it is quoted
|
# This is a quoted % operator - it is quoted
|
||||||
# because it can be used in strings that also
|
# because it can be used in strings that also
|
||||||
# have parameter substitution.
|
# have parameter substitution.
|
||||||
|
MOD = '%%'
|
||||||
|
|
||||||
# Bitwise operators - note that these are generated by .bitand()
|
# Bitwise operators - note that these are generated by .bitand()
|
||||||
# and .bitor(), the '&' and '|' are reserved for boolean operator
|
# and .bitor(), the '&' and '|' are reserved for boolean operator
|
||||||
|
@ -117,7 +117,24 @@ def _long_to_bin(x, hex_format_string):
|
|||||||
return binascii.unhexlify((hex_format_string % x).encode('ascii'))
|
return binascii.unhexlify((hex_format_string % x).encode('ascii'))
|
||||||
|
|
||||||
|
|
||||||
def pbkdf2(password, salt, iterations, dklen=0, digest=None):
|
if hasattr(hashlib, "pbkdf2_hmac"):
|
||||||
|
def pbkdf2(password, salt, iterations, dklen=0, digest=None):
|
||||||
|
"""
|
||||||
|
Implements PBDF2 with the same API as Django's existing implementation,
|
||||||
|
using the stdlib.
|
||||||
|
|
||||||
|
This is used in Python 3.4 and up.
|
||||||
|
"""
|
||||||
|
if digest is None:
|
||||||
|
digest = hashlib.sha256
|
||||||
|
if not dklen:
|
||||||
|
dklen = None
|
||||||
|
password = force_bytes(password)
|
||||||
|
salt = force_bytes(salt)
|
||||||
|
return hashlib.pbkdf2_hmac(
|
||||||
|
digest().name, password, salt, iterations, dklen)
|
||||||
|
else:
|
||||||
|
def pbkdf2(password, salt, iterations, dklen=0, digest=None):
|
||||||
"""
|
"""
|
||||||
Implements PBKDF2 as defined in RFC 2898, section 5.2
|
Implements PBKDF2 as defined in RFC 2898, section 5.2
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user