生成一个随机唯一的字符串

"""
生成随机的字符串 Token
"""

def get_random_str(username):
    import time, hashlib
    ctime = str(time.time())
    # print(ctime)
    # print(type(ctime))
    md5 = hashlib.md5(bytes(username, encoding="utf8"))
    md5.update(bytes(ctime, encoding="utf8"))
    # print(md5)
    # print(md5.hexdigest()) 获取md5的16进制字符串
    return md5.hexdigest()

get_random_str("alex")

 

posted @ 2020-12-16 21:32  Feng_fu  阅读(150)  评论(0编辑  收藏  举报