Skip to content

Commit 6174e72

Browse files
committed
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
1 parent e98abbf commit 6174e72

2 files changed

Lines changed: 15 additions & 7 deletions

File tree

ietf/utils/accesstoken.py

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
import time, random, hashlib
2+
3+
from django.conf import settings
4+
5+
def generate_random_key(max_length=32):
6+
"""Generate a random access token."""
7+
return hashlib.sha256(settings.SECRET_KEY + ("%.16f" % time.time()) + ("%.16f" % random.random())).hexdigest()[:max_length]
8+
9+
def generate_access_token(key, max_length=32):
10+
"""Make an access token out of key."""
11+
assert key, "key must not be empty"
12+
# we hash it with the private key to make sure only we can
13+
# generate and use the final token - so storing the key in the
14+
# database is safe
15+
return hashlib.sha256(settings.SECRET_KEY + key).hexdigest()[:max_length]

ietf/utils/uniquekey.py

Lines changed: 0 additions & 7 deletions
This file was deleted.

0 commit comments

Comments
 (0)