From 8ec15f9211aafd869aba2697eb4718743ea8be3c Mon Sep 17 00:00:00 2001 From: virusdefender <1670873886@qq.com> Date: Mon, 28 Mar 2016 17:46:56 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BD=BF=E7=94=A8=E6=9B=B4=E5=BC=BA=E7=9A=84?= =?UTF-8?q?=E9=9A=8F=E6=9C=BA=E7=AE=97=E6=B3=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- utils/shortcuts.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/utils/shortcuts.py b/utils/shortcuts.py index 2f0e1c65..83b95673 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