• 常见模块作业


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

    import hashlib
    m = hashlib.md5()
    def register():
        inp_name = input("请输入账号:").strip()
        inp_pwd = input("请输入密码:").strip()
        re_inp_pw = input("请再次输入密码:").strip()
        if inp_pwd==re_inp_pw:
            m.update(inp_pwd.encode("utf-8"))
            res = m.hexdigest()
            # print(res)
            with open("a.txt","a",encoding="utf-8")as f:
                f.write(f'{inp_name}:{res}
    ')
    
    def login():
        inp_name = input('输入账号').strip()
        inp_pwd = input('输入密码').strip()
        res = m.update(inp_pwd.encode('utf-8'))
        with open('a.txt','rt',encoding='utf-8')as f:
            for i in f:
                name,pwd = i.strip().split(':')
                if res == pwd and inp_name == name:
                    print('登入成功')
                    break
            else:
                print('登入失败')

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

    import hashlib
    m = hashlib.md5()
    def a():
        with open("a.txt","rt",encoding="utf-8")as f :
            l = [10, 20, 30]
            for i in l :
                f.seek(i,0)
                res = f.read(100)
                m.update(res.encode("utf-8"))
            res = m.hexdigest()
            return res
    
    def b():
        with open("b.txt","rt",encoding="utf-8")as f :
            l = [10,20,30]
            for i in l:
                f.seek(i,0)
                msg = f.read(5)
                m.update(msg.encode("utf-8"))
            res = m.hexdigest()
            if res == a():
                print("文件完整")
            else:
                print("文件不完整")

    3、注册功能改用json实现

    def register():
        inp_name = input("请输入账号:").strip()
        inp_pwd = input("请输入密码:").strip()
        re_inp_pw = input("请再次输入密码:").strip()
        if inp_pwd==re_inp_pw:
            with open("a.txt","a",encoding="utf-8")as f:
                json.dump(f'{inp_name}:{inp_pwd}',f)

    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'))
  • 相关阅读:
    VC 中Combo Box的使用 Chars
    毕业论文摘要的书写方法和技巧 Chars
    VC调用DLL Chars
    《CLR via C#》Part1之Chapter3 共享程序集和强命名程序集(二)
    委托的使用(转)
    新概念系列之《Lesson 133 Sensational news》
    《CLR via C#》Part1之Chapter2 生成、打包、部署及管理应用程序及类型
    新概念系列之《Part2 Lesson 17 Always young》
    新概念系列之《Part2 Lesson 4 An exciting trip》
    新概念系列之《Part2 Lesson 16 A polite request》
  • 原文地址:https://www.cnblogs.com/bk134/p/12607772.html
Copyright © 2020-2023  润新知