博客
关于我
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出现 RuntimeError: dictionary changed size during iteration 的解决方法
查看>>
Python-numpy(2)数组的操作
查看>>
Python-Numpy的tile函数用法
查看>>
python-open函数
查看>>
Python-Pandas-将特定函数应用于给定级别-多索引数据框架
查看>>
python-queue队列通信
查看>>
python-ros No module named PyKDL
查看>>
python-social-auth 是否需要会话
查看>>
Python再获年度编程语言,微软或成最大赢家
查看>>
python-week5
查看>>
Python写表情包搜索工具(非常详细)零基础入门到精通,收藏这一篇就够了
查看>>
Python-【1】配置
查看>>
Python-从子文件夹执行绝对导入
查看>>
Python-刷新页面,直到元素可单击
查看>>
PYTHON-唤醒+VOSK+DEEPSEEK+离线合成-实现纯离线大模型问答
查看>>
Python-在Dash回调中重用函数
查看>>
PYTHON-基本数据类型-元祖类型,字典类型,集合类型
查看>>
python-外观模式
查看>>
Python-如何使用FastAPI和uvicorn.run而不阻塞线程?
查看>>
Python-字典
查看>>