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'))
  • 相关阅读:
    HTML5 API的威力
    国内独立博客发展的障碍
    中国天气 XWeahter 2.0.1.0 所有版本 下载地址 阿干 win7
    宿命轮回里的爱与恨
    广东一伙劫匪在抢劫银行时说了一句至理名言
    Android项目R文件丢失报错
    2010年8月29日周日_Creating a New Xcode Project_3
    2010年8月27日周五understanding ArcGIS Server_secured services_8.4
    2010年8月26日_TitleWindow_Flex控件
    组件类_BorderContainer1
  • 原文地址:https://www.cnblogs.com/lucky-cat233/p/12609044.html
Copyright © 2011-2022 走看看