zoukankan      html  css  js  c++  java
  • emmm......就当练习了系列18

    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
    import random
    import os
    
    def get_md5(file_path):
        size=os.path.getsize(file_path)
        bytes_size=size*8
        list_seek=[int(bytes_size/4),int(bytes_size/3),int(bytes_size/2)]
        with open(file_path,"rb") as f:
            m1=hashlib.md5()
            for i in range(3):
                f.seek(i,0)
                data=f.read(7)
                m1.update(data)
        res=m1.hexdigest()
        return res
    
    # res=get_md5(r"E:oldboyclasswork
    eader_system
    eadme.txt")
    # print(res)    #a5d2db97ffa024feeb87b56b9410eca7
    
    #将文件改变前的md5存下来
    res="a5d2db97ffa024feeb87b56b9410eca7"
    def change_file(file_path):
        size=os.path.getsize(file_path)
        # print(size)
        bytes_size=size*8
        list_seek=[int(bytes_size/4),int(bytes_size/3),int(bytes_size/2)]
        with open(file_path,"rb") as f:
            m1=hashlib.md5()
            for i in range(3):
                f.seek(i,0)
                data=f.read(7)
                m1.update(data)
        result=m1.hexdigest()
        print(result)
        if result == res:
            print("文件完整")
        else:
            print("文件已损坏")
    
    change_file(r"E:oldboyclasswork
    eader_system
    eadme.txt")


    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
    
    config=configparser.ConfigParser()
    config.read(settings.py)
    print(config.sections())
    
    print(config.options('section1'))
    
    print(config.items('section1'))
  • 相关阅读:
    vue 自定义指令
    vue 插槽
    vue 菜单跳转 页面错乱
    vue项目中使用elementUI的el-tabs组件 浏览器卡死问题 解决办法
    vue 环境配置
    移动端页面 问题 注意事项
    定义全局 强制刷新指令
    手机端样式 处理
    手机访问电脑本地开发的页面
    百度AI
  • 原文地址:https://www.cnblogs.com/lucky-cat233/p/12609044.html
Copyright © 2011-2022 走看看