zoukankan      html  css  js  c++  java
  • 常见模块作业

    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'))
  • 相关阅读:
    .net中实现运行时从字符串动态创建对象
    C# 用 VB.net 函數庫 實現全角與半角轉換
    實現.net 加載插件方式
    VS2008下載
    Lotus Notes Send EMail from VB or VBA
    用C#写vs插件中的一些Tip
    SQL2005中异常处理消息框可直接使用
    C#路径/文件/目录/I/O常见操作汇总
    利用.net反射动态调用指定程序集的中的方法
    说说今年的计划
  • 原文地址:https://www.cnblogs.com/bk134/p/12607772.html
Copyright © 2011-2022 走看看