Skip to content

Commit a3d40ac

Browse files
committed
Fixed a str/bytes issue with a hashlib function call, and removed an unused import.
- Legacy-Id: 16398
1 parent e55c42b commit a3d40ac

1 file changed

Lines changed: 3 additions & 2 deletions

File tree

ietf/utils/accesstoken.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,8 @@
22
import time, random, hashlib
33

44
from django.conf import settings
5-
from django.utils.encoding import force_bytes
5+
from django.utils.encoding import force_bytes, force_text
6+
67

78
def generate_random_key(max_length=32):
89
"""Generate a random access token."""
@@ -14,4 +15,4 @@ def generate_access_token(key, max_length=32):
1415
# we hash it with the private key to make sure only we can
1516
# generate and use the final token - so storing the key in the
1617
# database is safe
17-
return hashlib.sha256(force_bytes(settings.SECRET_KEY) + force_bytes(key)).hexdigest()[:max_length]
18+
return force_text(hashlib.sha256(force_bytes(settings.SECRET_KEY) + force_bytes(key)).hexdigest()[:max_length])

0 commit comments

Comments
 (0)