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:
Ole Laursen 2013-11-15 16:07:10 +00:00
parent e98abbf56d
commit 6174e72036
2 changed files with 15 additions and 7 deletions

15
ietf/utils/accesstoken.py Normal file
View 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]

View file

@ -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]