day23 作业
2024-09-07 19:18:17
day23 作业
1、把登录与注册的密码都换成密文形式
import hashlib
def register():
m = hashlib.md5()
username = input("请输入要注册的账号:")
password = input("请输入要注册的密码:")
password2 = input("请再次输入的密码:")
if password==password2:
m.update(password.encode("utf-8"))
res = m.hexdigest()
print(res)
with open("db.txt","a",encoding="utf-8")as f:
f.write(f'{username}:{res}\n')
def login():
user_inp = input("请输入你的账号:")
pwd_inp = input("请输入你的密码:")
with open("db.txt","r",encoding="utf-8")as f1:
user = hashlib.md5()
user.update(pwd_inp.encode("utf-8"))
res = user.hexdigest()
for line in f1:
username,password = line.strip().split(":")
if user_inp ==username:
if res == password:
print("登录成功")
return
else:
print('密码错误')
else:
print("账号不存在")
register()
login()
2、文件完整性校验(考虑大文件)
def official_file_hx():
with open("official_file","rt",encoding="utf-8")as f :
l = [20, 30, 40]#l根据需求改变
m = hashlib.md5()
for i in l :
f.seek(i,0)
res = f.read(5)
m.update(res.encode("utf-8"))
res = m.hexdigest()
return res
def download_file_hx():
with open("download_file","rt",encoding="utf-8")as f :
l = [20,30,40]
m = hashlib.md5()
for i in l:
f.seek(i,0)
msg = f.read(5)
m.update(msg.encode("utf-8"))
res = m.hexdigest()
if res == official_file_hx():
print("文件完整")
else:
print("文件不完整")
download_file_hx()
3、注册功能改用json实现
import json
def register():
m = hashlib.md5()
username = input("请输入要注册的账号:")
password = input("请输入要注册的密码:")
password2 = input("请再次输入的密码:")
if password==password2:
m.update(password.encode("utf-8"))
res = m.hexdigest()
print(res)
with open("db.txt","a",encoding="utf-8")as f:
# f.write(f'{username}:{res}\n')
user_dict = {username:res}
json.dump(user_dict, f)
register()
4、项目的配置文件采用configparser进行解析
text.ini
[section1]
k1 = v1
k2:v2
user=egon
age=18
is_admin=true
salary=31
[section2]
k1 = v1
import configparser
config = configparser.ConfigParser()
config.read('text.ini')
print(config.sections())
print(config.options('section1'))
print(config.items('section1'))
res= config.get('section1','is_admin')
print(res,type(res))
print(config.getint('section1','age'))
print(config.getfloat('section1','age'))
print(config.getboolean('section1','is_admin'))
最新文章
- WCF学习之旅—WCF服务的Windows 服务程序寄宿(十一)
- Boost学习笔记(一) 什么是Boost
- 作业七:团队项目——Alpha版本冲刺阶段-12
- [PCB设计] 2、畸形PCB板子的制作核心——AD14导入dwg格式文件的方法
- POSIX信号处理
- python之装饰器详解
- nchar 和 nvarchar
- bzoj 3110 [Zjoi2013]K大数查询(树套树)
- [C#]Thread Safe Dictionary in .NET 2.0
- [Linked List]Rotate List
- c 判断水仙花数,质数(素数)
- 微信jsSDK公众号开发时网页提示 invalid signature错误的解决方法
- Maven依赖分析
- python制作wifi破解(跑字典(单线程))
- 三十天学不会TCP,UDP/IP网络编程 - UDP的实践--DHCP
- 正则去除html字符串中的注释、标签、属性
- 2017.4.4 TCP/IP协议栈
- Linux 更改时区
- 【UVA】1589 Xiangqi(挖坑待填)
- cubemap
热门文章
- 被迫重构代码,这次我干掉了 if-else
- nacos部署注意点
- while or if
- Android官方新推的DI库 Hilt
- EIGRP-16-其他和高级的EIGRP特性-2-非等价负载分担
- 完美解决PYQT5登录界面跳转主界面方法
- ojdbc6中OraclePreparedStatement的ArrayIndexOutOfBoundsException异常BUG-6396242
- 【JMeter_10】JMeter逻辑控制器__ForEach控制器<;ForEach Controller>;
- cookie与session区别?
- Vue中hash模式和history模式的区别