博客
关于我
hashlib 简单加密
阅读量:440 次
发布时间:2019-03-06

本文共 1372 字,大约阅读时间需要 4 分钟。

        ```python        import hashlib        def md5(arg):            # 定义一个加密处理函数            md5_pwd = hashlib.md5()            md5_pwd.update(bytes(arg, encoding='utf-8'))            return md5_pwd.hexdigest()        def log(user, pwd):            # 定义一个验证登录功能的函数            try:                with open('login', 'r', encoding='utf-8') as f:                    for line in f:                        u, p = line.strip().split('|')                        if u == user and p == md5(pwd):                            return True                return False            except:                return False        def register(user, pwd):            # 定义一个用户注册功能的函数            with open('login', 'a', encoding='utf-8') as f:                temp = f"{user}|{md5(pwd)}"                f.write(temp)        while True:            m = input('请选择功能:1.登录,2.注册')            if m == '1':                user = input('请输入登录账号:')                pasw = input('请输入登录账号密码:')                if log(user, pasw):                    print('登录成功')                else:                    print('登录失败,请系统推出')                break            elif m == '2':                user = input('请输入注册账号:')                pasw = input('请输入注册账号密码:')                register(user, pasw)                print('注册成功')                break            else:                print('功能不存在')                break        ```    

转载地址:http://ccjyz.baihongyu.com/

你可能感兴趣的文章
Python:Google API - 从消息中获取 mimeTypes
查看>>
Python:Google API - 从消息中获取 mimeTypes
查看>>
Python:subprocess.call,stdout to file,stderr to file,在屏幕上实时显示stderr
查看>>
Python:TypeError:无法连接“str“和“int“对象
查看>>
Python:XPath 在 ElementTree 中不可用
查看>>
Python:从 FTP 服务器下载文件
查看>>
python:从列表中创建元组列表
查看>>
Python:从嵌套列表中删除重复项
查看>>
Python:从间隔映射到值
查看>>
Python:使用 shell=False 的子进程调用不起作用
查看>>
Python:修改 PATH 环境变量的平台无关方式
查看>>
Python:假与 0
查看>>
Python:函数使用
查看>>
Python:函数进阶
查看>>
Python:在整数的二进制表示中查找最长的二进制间隙
查看>>
Python:如何从二进制转换为 base 64 并返回?
查看>>
Python:如何以非阻塞方式读取子进程的标准输出
查看>>
Python:如何使用 plotly 制作阴影区域或交替背景颜色?
查看>>
Python:如何根据日期时间获取值的计数
查看>>
python:如何检测串行 COM 上的设备名称/ID
查看>>