• 3.31作业


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

    def login():
        ipt_name = input('请输入帐号:').strip()
        ipt_pwd = input('请输入密码:').strip()
        pwd_hash = hashlib.md5(ipt_pwd.encode('utf-8'))
        with open('db.txt','rt',encoding='utf-8') as f:
            for i in f:
                if [ipt_name,pwd_hash.hexdigest()] == i.strip('
    ').split(':'):
                    print('login succ')
                    break
            else:
                print('输入账号或者密码错误')
    
    def register():
        ipt_account = input('Enter your account:')
        ipt_pwd = input('Enter your password:')
        with open('db.txt','at',encoding='utf-8') as f:
            pwd_hash = hashlib.md5(ipt_pwd.encode('utf-8'))
            f.write(f'{ipt_account}:{pwd_hash.hexdigest()}
    ')
        login()
    
    register()
    

      

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

    import hashlib
    import os
    import random
    def check_file(file1,file2):
        m1 = hashlib.md5()
        m2 = hashlib.md5()
        lis = []
        file_size = os.path.getsize(file1)
        with open(file1,'rb') as f,
                open(file2,'rb') as g:
            for i in range(10):
                lis.append(random.randint(0,file_size-20))
            for i in lis:
                f.seek(i)
                g.seek(i)
                dataf = f.read(20)
                m1.update(dataf)
                datag = g.read(20)
                m2.update(datag)
        file1_hash = m1.hexdigest()
        file2_hash = m2.hexdigest()
        print(file1_hash == file2_hash)
    
    check_file('3.31day笔记.md','3.31day笔记_download.md')
    

      

    注册功能改用json实现

    import hashlib,json
    
    def register():
        ipt_name = input('请输入用户名:').strip()
        ipt_pwd = input('请输入密码:').strip()
        with open('db.txt','at',encoding='utf-8') as f:
            pwd_hash = hashlib.md5(ipt_pwd.encode('utf-8'))
            register_info = {
                'name':ipt_name,
                'password':pwd_hash.hexdigest(),
                'account_type':'user'
            }
            json.dump(f"{ipt_name}:{register_info}",f)
            f.write('
    ')
    
    register()

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

  • 相关阅读:
    rsync的man手册(未完成)
    rsync基础
    命令:mktemp
    命令:install
    [Abp vNext 源码分析]
    异常吞噬问题一则
    使用 Polly 实现复杂策略(超时重试)
    在 DotNetty 中实现同步请求
    使用 C# 实现 CJ-T188 水表协议和 DL-T645 电表协议的解析与编码
    DevExpress 使用 GridControl 时,数据源无法立即更新的问题
  • 原文地址:https://www.cnblogs.com/Tornadoes-Destroy-Parking-Lots/p/12608164.html
Copyright © 2020-2023  润新知