diff --git a/utils/shortcuts.py b/utils/shortcuts.py index 2f0e1c6..83b9567 100644 --- a/utils/shortcuts.py +++ b/utils/shortcuts.py @@ -1,4 +1,5 @@ # coding=utf-8 +import os import hashlib import time import random @@ -107,5 +108,6 @@ def paginate(request, query_set, object_serializer=None): def rand_str(length=32): - string = hashlib.md5(str(time.time()) + str(random.randrange(1, 987654321234567)) + str(random.randrange(1, 987654321234567))).hexdigest() - return string[0:length] \ No newline at end of file + if length > 128: + raise ValueError("length must <= 128") + return hashlib.sha512(os.urandom(128)).hexdigest()[0:length] \ No newline at end of file