# 作业:
# 1、把登录与注册的密码都换成密文形式
'''
import hashlib
def register():
s = hashlib.md5()
username = input('请输入用户名: ').strip()
s.update(username.encode('utf-8'))
s1 = s.hexdigest()
password = input('请输入密码: ').strip()
re_password = input('请输入密码: ').strip()
s.update(password.encode('utf-8'))
s2 = s.hexdigest()
print(s1,s2)
if password == re_password:
with open('user.txt',mode='at',encoding='utf-8')as f:
f.write('{}:{}'.format(s1,s2))
print(f'[{username}]注册成功')
else:
print('注册失败!')
register()
'''
'''
import hashlib
dic={}
def login():
while True:
with open('user.txt',mode='rt',encoding='utf-8')as f:
for line in f:
user,pwd=line.strip().split(':')
dic[user]=pwd
username = input('请输入用户名: ').strip()
s = hashlib.md5()
s.update(username.encode('utf-8'))
s1 = s.hexdigest()
if s1 in dic:
password = input('请输入密码: ').strip()
s.update(password.encode('utf-8'))
s2 = s.hexdigest()
if s2 == dic[s1]:
print('登录成功!')
pass
else:
print('登录失败!')
else:
print('用户名不存在,请重新输入或注册!')
pass
login()
'''
# 2、文件完整性校验(考虑大文件)
'''
有问题
import hashlib
with open(r'01 json与pickle模块.py', mode='rt',encoding='utf-8') as f1,open('new.py',mode='wt',encoding='utf-8')as f2:
data1 = f1.read()
s = hashlib.md5()
s.update(data1.encode('utf-8'))
s1 = s.hexdigest()
print(s1)
f2.write(data1)
while True:
with open('new.py',mode='rt',encoding='utf-8')as f3:
data2=f3.read()
s.update(data1.encode('utf-8'))
s2 = s.hexdigest()
print(s2)
if s1 == s2:
print('复制成功!')
else:
print('复制失败!')
break
'''
# 3、注册功能改用json实现
'''
import json
def register():
username = input('请输入用户名: ').strip()
username=json.dumps(username)
password = input('请输入密码: ').strip()
re_password = input('请输入密码: ').strip()
if password == re_password:
password = json.dumps(password)
with open('user.txt',mode='at',encoding='utf-8')as f:
f.write('{}:{}\n'.format(username,password))
print(f'[{username}]注册成功')
else:
print('注册失败!')
register()
'''
# 4、项目的配置文件采用configparser进行解析
'''
有问题
import configparser
s=configparser.ConfigParser()
s.read('settings.ini')
print(s.sections())
'''