python学习之路-生成随机数和md5加密

import random
import hashlib

seed = "1234567890abcdefghijklmnopqrstuvwxyz"
sa = []
for i in range(8):
    sa.append(random.choice(seed))
salt = ''.join(sa)
print (salt)   #打印显示的随机字符
hash = hashlib.md5()
hash.update(salt.encode())
md5_test = hash.hexdigest()
print(md5_test)       #打印加密后的md5值

#输入结果
lbyqejti
8f0680a5ee6e5aea4aca5f3b5f5472ae

你可能感兴趣的:(python)