使用更强的随机算法
This commit is contained in:
@@ -1,4 +1,5 @@
|
|||||||
# coding=utf-8
|
# coding=utf-8
|
||||||
|
import os
|
||||||
import hashlib
|
import hashlib
|
||||||
import time
|
import time
|
||||||
import random
|
import random
|
||||||
@@ -107,5 +108,6 @@ def paginate(request, query_set, object_serializer=None):
|
|||||||
|
|
||||||
|
|
||||||
def rand_str(length=32):
|
def rand_str(length=32):
|
||||||
string = hashlib.md5(str(time.time()) + str(random.randrange(1, 987654321234567)) + str(random.randrange(1, 987654321234567))).hexdigest()
|
if length > 128:
|
||||||
return string[0:length]
|
raise ValueError("length must <= 128")
|
||||||
|
return hashlib.sha512(os.urandom(128)).hexdigest()[0:length]
|
||||||
Reference in New Issue
Block a user