Fixed a str/bytes issue with a hashlib function call, and removed an unused import.
- Legacy-Id: 16398
This commit is contained in:
parent
e55c42b20f
commit
a3d40ace9b
|
@ -2,7 +2,8 @@
|
|||
import time, random, hashlib
|
||||
|
||||
from django.conf import settings
|
||||
from django.utils.encoding import force_bytes
|
||||
from django.utils.encoding import force_bytes, force_text
|
||||
|
||||
|
||||
def generate_random_key(max_length=32):
|
||||
"""Generate a random access token."""
|
||||
|
@ -14,4 +15,4 @@ def generate_access_token(key, max_length=32):
|
|||
# we hash it with the private key to make sure only we can
|
||||
# generate and use the final token - so storing the key in the
|
||||
# database is safe
|
||||
return hashlib.sha256(force_bytes(settings.SECRET_KEY) + force_bytes(key)).hexdigest()[:max_length]
|
||||
return force_text(hashlib.sha256(force_bytes(settings.SECRET_KEY) + force_bytes(key)).hexdigest()[:max_length])
|
||||
|
|
Loading…
Reference in a new issue