zoukankan      html  css  js  c++  java
  • 作业3月31号

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

    import hashlib
    def register():
        user=input('请输入账号:')
        pwd=input('请输入密码:')
        pwd1=hashlib.md5(pwd.encode('utf-8'))
        pwd2=pwd1.hexdigest()
        with open('a.txt','a',encoding='utf-8') as f:
            f.write('{}:{}
    '.format(user,pwd2))
    register()
    
    def login():
        user = input('请输入账号:')
        pwd = input('请输入密码:')
        pwd1 = hashlib.md5(pwd.encode('utf-8'))
        pwd2 = pwd1.hexdigest()
        with open('a.txt', 'r', encoding='utf-8') as f:
            for line in f:
                if [user,pwd2] == line.strip().split(':'):
                    print('登录成功')
    login()

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

    import hashlib
    
    def verify_file(file):
        m = hashlib.md5()
        res = [100, 200, 300, 400]
        with open(file, 'rb') as f:
            for line in res:
                f.seek(line, 0)
                m.update(f.read(100))
    
            return m.hexdigest()


    3、注册功能改用json实现

    import hashlib,json
    
    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'))
            register_info = {
                'name':ipt_account,
                'password':pwd_hash.hexdigest(),
                'account_type':'user'
            }
            json.dump(f"{ipt_account}:{register_info}",f)
            f.write('
    ')
    
    register()


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

    def config_parser(section, option, type=str):
        import configparser
        from conf.settings import CONF_INI_FILE
    
        config = configparser.ConfigParser()
        config.read(CONF_INI_FILE)
        if type == int:
            return config.getint(section, option)
        return config.get(section, option)
  • 相关阅读:
    清除浮动float
    overflow属性
    轮播图的小圆圈鼠标移上去变样式
    大banner居中
    网站logo
    VS里面设置类似于#1或者#2之类的程序快捷输入
    优先级运算简单顺口溜
    对2的次幂求模
    VS2019离线安装
    unity ContentSizeFitter设置verticalFit立即生效
  • 原文地址:https://www.cnblogs.com/jingpeng/p/12609066.html
Copyright © 2011-2022 走看看