3/31

1、把登录与注册的密码都换成密文形式

import hashlib

username = input('请输入账号: ').strip()
password = input('请输入密码: ').strip()
re_password = input('请再次输入密码: ').strip()
if password == re_password:
    with open('db.txt', 'a', encoding='utf-8')as f:
        m_password = hashlib.md5(password.encode('utf-8'))
        res = f'{username}:{m_password}\n'
        f.write(res)
else:
    print('两次密码不一致!')
   
   
username = input('请输入账号:').strip()
password = input('请输入密码:').strip()
with open('db.txt', 'r', encoding='utf-8')as f:
    for line in f:
        name, pwd = f.read().strip().split(':')
        m_pwd = hashlib.md5(password)
        if m_pwd == pwd and username == name:
            print('login sucess!')
    else:
        print('id or password error!')

2、文件完整性校验(考虑大文件)

def hash(path):
    with open(path, 'rb', encoding='utf-8')as h_f:
        l = [0, 50, 100]
        m = hashlib.md5()
        for i in l:
            h_f.seek(i, 0)
            res = h_f.read(100)
            m.update(res.encode('utf-8'))
        res2 = m.hexdigest()
        return res2


if hash(old) == hash(new):
    print('文件校验成功')
else:
    print('文件下载失败!')

3、注册功能改用json实现

4、项目的配置文件采用configparser进行解析

import configparser

config = configparser.ConfigParser()
config.read('test.ini')

config.sections()  # 获取ini目录下的section信息

config.options('section1'# 获取section1下的详细信息 (key)

config.get('section1', 'user'# 查看section1 下user的信息 字符串的格式

config.items("section1"# 查看section1的信息(key:val)

config.getint()('section1', 'age'# 返回整数

config.getfloat('section1', 'age'# 返回浮点数

config.getboolean('section1', 'is_admin'# 返回布尔值

猜你喜欢

转载自www.cnblogs.com/bailongcaptain/p/12608744.html