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

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

    import hashlib
    
    pwd = input('请输入密码:').strip()
    with open('db.txt','a',encoding='utf-8') as f:
        hash1 = hashlib.md5(pwd.encode('utf-8'))
        print(hash1.hexdigest(),type(hash1.hexdigest()))
        f.write(hash1.hexdigest() + '
    ')
    

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

    import hashlib
    def copy():
        with open('db.txt','rb') as f1,
            open('db1.txt','wb') as f2:
            f2.write(f1.read())
    
    copy()
    
    with open('db.txt','rb') as f:
        d = []
        a = f.read(10)
        while a:
            m = hashlib.md5(a)
            d.append(m.hexdigest())
            f.seek(10, 1)
            a = f.read(10)
    
    print(d)
    with open('db1.txt','rb') as f:
        d1 = []
        a = f.read(10)
        while a:
            m = hashlib.md5(a)
            d1.append(m.hexdigest())
            f.seek(10,1)
            a = f.read(10)
    print(d1)
    for i in range(len(d)):
        if d[i] != d1[i]:
            print('文件不完整')
            break
    else:
        print('文件完整')
    

    3、注册功能改用json实现

    import json,hashlib
    def register():
        user = input('请输入账号:').strip()
        pwd = input('请输入密码:').strip()
        pwd1 = input('请确认密码:').strip()
        if pwd == pwd1:
            import hashlib
            m = hashlib.md5(pwd.encode('utf-8'))
            m = m.hexdigest()
            with open('db.txt','a',encoding='utf-8') as f:
                json.dump('{}:{}:{}'.format(user,m,0),f)
                print('注册成功')
        else:
            print('密码不一致')
    register()
    

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

    import configparser as conf
    
    settings = conf.ConfigParser()
    settings.read('conf.txt')
    print(settings.sections())
    print(settings.items('section1'))
    
  • 相关阅读:
    .net验证是否合法邮箱和ip地址的方式
    .net通用类型转换方法
    asp.net中的<%%>的使用
    autofac初识
    .net面试题
    asp.net使用一般处理程序实现文件下载
    asp.net 一般处理程序接收上传文件的问题
    Python学习日记(十八) 序列化模块
    Python学习日记(十七) os模块和sys模块
    Python学习日记(十六) time模块和random模块
  • 原文地址:https://www.cnblogs.com/pythonwl/p/12606633.html
Copyright © 2011-2022 走看看