zoukankan      html  css  js  c++  java
  • PYthon-3.31作业

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

    import hashlib
    def register():
        m = hashlib.md5()
        username = input("请输入要注册的账号:")
        password = input("请输入要注册的密码:")
        password2 = input("请再次输入的密码:")
        if password==password2:
            m.update(password.encode("utf-8"))
            res = m.hexdigest()
            print(res)
            with open("db.txt","a",encoding="utf-8")as f:
                f.write(f'{username}:{res}
    ')
    
    def login():
        user_inp = input("请输入你的账号:")
        pwd_inp = input("请输入你的密码:")
        with open("db.txt","r",encoding="utf-8")as f1:
            user = hashlib.md5()
            user.update(pwd_inp.encode("utf-8"))
            res = user.hexdigest()
            for line in f1:
                username,password = line.strip().split(":")
                if user_inp ==username:
                    if res == password:
                        print("登录成功")
                        return
                    else:
                        print('密码错误')
            else:
                print("账号不存在")
    register()
    login()

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

    def official_file_hx():
        with open("official_file","rt",encoding="utf-8")as f :
            l = [20, 30, 40]#l根据需求改变
            m = hashlib.md5()
            for i in l :
                f.seek(i,0)
                res = f.read(5)
                m.update(res.encode("utf-8"))
            res = m.hexdigest()
            return res
    
    def download_file_hx():
        with open("download_file","rt",encoding="utf-8")as f :
            l = [20,30,40]
            m = hashlib.md5()
            for i in l:
                f.seek(i,0)
                msg = f.read(5)
                m.update(msg.encode("utf-8"))
            res = m.hexdigest()
            if res == official_file_hx():
                print("文件完整")
            else:
                print("文件不完整")
    
    download_file_hx()

    3、注册功能改用json实现

    import json
    
    def register():
        m = hashlib.md5()
        username = input("请输入要注册的账号:")
        password = input("请输入要注册的密码:")
        password2 = input("请再次输入的密码:")
        if password==password2:
            m.update(password.encode("utf-8"))
            res = m.hexdigest()
            print(res)
            with open("db.txt","a",encoding="utf-8")as f:
                # f.write(f'{username}:{res}
    ')
                user_dict = {username:res}
                json.dump(user_dict, f)
    register()


    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'))


  • 相关阅读:
    IOS动态类型isKindOfClass, isMemberOfClass
    IOS-sqlite3数据库: create table数据库表及对数据库表的增删改查(create/insert/delete)
    TCP/UDP区别
    IOS中的NSData和NSFileManager例子微解
    IOS TableView的Delegate Methods-tableView didSelectRowAtIndexPath
    IOS IPA打包和真机测试
    使用autolayout的NSLayoutConstraint类中的constraintWithItem 、constraintsWithVisualFormat这两个类方法来创建视图并可以实现自动布局
    自定义圆形进度条
    通过cagradientLayer类封装uiimageview动画色度差
    通过CAGradientLayer类实现色度差动画
  • 原文地址:https://www.cnblogs.com/lijunc/p/12607750.html
Copyright © 2011-2022 走看看