# 1、把登录与注册的密码都换成密文形式
# import hashlib
# def register():
# m=hashlib.md5()
# user=input('请输入用户名:')
# pwd=input('请输入密码:')
# re_pwd=input('请输入密码:')
# if pwd==re_pwd:
# m.update(pwd.encode('utf-8'))
# res=m.hexdigest()
# with open('db.txt',mode='at',encoding='utf-8')as f:
# f.write(f'{user}:{res}
')
# else:
# print('两次密码不一致')
#
# dic={}
# def login():
# user = input('请输入用户名:')
# with open('db.txt', mode='rt', encoding='utf-8')as f:
# for line in f:
# username,password=line.strip().strip(':')
# dic[username]=password
# if user in username:
# pwd = input('请输入密码:')
# m=hashlib.md5(pwd)
# res=m.hexdigest
# if res==dic[username]:
# print('登录成功')
# else:
# pass
# else:
# pass
# 2、文件完整性校验(考虑大文件)
import hashlib
def srt_file():
with open('srt_file_txt',mode='rb')as f1:
m=hashlib.md5()
for i in [0,150,300]:
f1.seek(i,0)
res=f1.read(50)
m.update(res)
content=m.hexdigest
return content
def dst_file():
with open('dst_file_txt',mode='rb')as f2:
m=hashlib.md5()
for i in [0,150,300]:
f2.seek(i,0)
res=f2.read(50)
m.update(res)
content2=m.hexdigest
if content2==srt_file():
print('文件一致')
else:
print('文件不一致')
# 3、注册功能改用json实现
import hashlib
import json
def register():
m=hashlib.md5()
user=input('请输入用户名:')
pwd=input('请输入密码:')
re_pwd=input('请输入密码:')
if pwd==re_pwd:
m.update(pwd.encode('utf-8'))
res=m.hexdigest()
with open('db.txt',mode='at',encoding='utf-8')as f:
json.dump(f'{user}:{res}
',f)
else:
print('两次密码不一致')
# 4、项目的配置文件采用configparser进行解析