File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 1+ # Copyright The IETF Trust 2013-2019, All Rights Reserved
12import time , random , hashlib
23
34from django .conf import settings
5+ from django .utils .encoding import force_bytes
46
57def generate_random_key (max_length = 32 ):
68 """Generate a random access token."""
7- return hashlib .sha256 (settings .SECRET_KEY + ("%.16f" % time .time ()) + ("%.16f" % random .random ())).hexdigest ()[:max_length ]
9+ return hashlib .sha256 (force_bytes ( settings .SECRET_KEY ) + (b "%.16f" % time .time ()) + (b "%.16f" % random .random ())).hexdigest ()[:max_length ]
810
911def generate_access_token (key , max_length = 32 ):
1012 """Make an access token out of key."""
1113 assert key , "key must not be empty"
1214 # we hash it with the private key to make sure only we can
1315 # generate and use the final token - so storing the key in the
1416 # database is safe
15- return hashlib .sha256 (settings .SECRET_KEY + key ).hexdigest ()[:max_length ]
17+ return hashlib .sha256 (force_bytes ( settings .SECRET_KEY ) + force_bytes ( key ) ).hexdigest ()[:max_length ]
You can’t perform that action at this time.
0 commit comments