博客
关于我
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中对象的布尔值
查看>>
python中对集合的操作
查看>>
python中将列表转换为元组的时间复杂度,反之亦然
查看>>
Python中布尔表达式的求值
查看>>
python中很常用的10个内置函数整理(初学必备)
查看>>
python中打印二维列表数据
查看>>
python中打散数组shuffle
查看>>
Python中执行外部命令
查看>>
Python中拼接numpy数组-ChatGPT4o作答
查看>>
Python中提示:no module named 'PIL'
查看>>
Python中提示:UnicodeDecodeError: 'ascii' codec can't decode byte 0xe5 in position
查看>>
python中数据类型存储_浅谈Python中的数据类型
查看>>
python中文件最重要的功能是什么-学 Python 都用来干嘛的?
查看>>
python中文版语言_高盛最新调查:Python超过汉语成为未来最重要技能,你准备学哪种编程语言?...
查看>>
Python中文问题SyntaxError
查看>>
Python中方括号和括号括起来的列表有什么区别?
查看>>
python中时间处理_Python中处理时间的几种方法小结
查看>>
Python中枚举串口(包括虚拟端口)的跨平台方法是什么?
查看>>
python中根号下a怎么写_python中根号怎么表示
查看>>
Python中正则表达式的巧妙使用
查看>>