#注册
import hashlib #导入加密算法
username =input('username:')
pwd =input('pwd:')
md5 =hashlib.md5() #初始化加密模板
md5.update(pwd.encode('utf-8')) #添加要加密的字节
m =md5.hexdigest() #进行加密
print(m)
f =open('da123.txt','w',encoding='utf-8') #创建文件
f.write(f'{username}:{m}')
f.close()
#登录
username1 =input('username:')
pwd1 =input('pwd:')
md5 =hashlib.md5()
md5.update(pwd1.encode('utf-8'))
m1 =md5.hexdigest()
print(m1)
f=open('da123.txt','r',encoding='utf-8') #打开文件
for i in f:
username,m =i.strip().split(":")
if username ==username1 and m1 ==m:
print("登录成功")
break
else:
print("用户名或密码错误请重新登录")
f.close()