- md5实现注册
import hashlib
def md5(data_string):
obj = hashlib.md5()
obj.update(pwd.encode('utf-8'))
return obj.hexdigest() #密文
line = f'{user},{encrypt}\n'
#实现用户注册,密码加密
user = input('输入用户:')
pwd = input('输入密码')
with open ('db.txt','a',encoding='utf-8')as f:
f.write(line)
- md5封装成函数版本
def md5(data_string):
obj = hashlib.md5()
obj.update(data_string.encode('utf-8'))
return obj.hexdigest() # 密文
# 实现用户注册,密码加密
user = input('输入用户:')
pwd = input('输入密码')
encrypt = md5(pwd)
line = f'{user},{encrypt}\n'
with open('db.txt', 'a', encoding='utf-8') as f:
f.write(line)
标签:01,obj,pwd,user,注册,utf,line,md5
From: https://www.cnblogs.com/jhchena/p/18432471