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)
  • 相关阅读:
    编辑器 --- Visual Studio Code 英文界面转换成中文(简体)
    CSS3 -- column 实现瀑布流布局
    CSS3 -- 边框圆角
    CSS3 -- 弹性盒
    自适应布局要素
    Vue -- 基础知识
    Vue -- element-ui el-table 的合计在第一行显示并可点击
    如何在网页标题栏title加入logo(icon)图标?
    linux下暴力破解工具hydra【转】
    linux 服务简介
  • 原文地址:https://www.cnblogs.com/jingpeng/p/12609066.html
Copyright © 2011-2022 走看看