We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent e98abbf commit 6174e72Copy full SHA for 6174e72
2 files changed
ietf/utils/accesstoken.py
@@ -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
0 commit comments