Rename unique key to random key as it is not really unique, add function for generating an access token from the key
- Legacy-Id: 6716
This commit is contained in:
parent
e98abbf56d
commit
6174e72036
15
ietf/utils/accesstoken.py
Normal file
15
ietf/utils/accesstoken.py
Normal file
|
@ -0,0 +1,15 @@
|
|||
import time, random, hashlib
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
def generate_random_key(max_length=32):
|
||||
"""Generate a random access token."""
|
||||
return hashlib.sha256(settings.SECRET_KEY + ("%.16f" % time.time()) + ("%.16f" % random.random())).hexdigest()[:max_length]
|
||||
|
||||
def generate_access_token(key, max_length=32):
|
||||
"""Make an access token out of key."""
|
||||
assert key, "key must not be empty"
|
||||
# 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(settings.SECRET_KEY + key).hexdigest()[:max_length]
|
|
@ -1,7 +0,0 @@
|
|||
import time, random, hashlib
|
||||
|
||||
from django.conf import settings
|
||||
|
||||
def generate_unique_key(max_length=32):
|
||||
return hashlib.sha256(settings.SECRET_KEY + ("%.16f" % time.time()) + ("%.16f" % random.random())).hexdigest()[:max_length]
|
||||
|
Loading…
Reference in a new issue