博客
关于我
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中del函数的垃圾回收
查看>>
Python中DrissionPage的详细解析与实战
查看>>
python中enumerate、变量类型转换
查看>>
python中execute是啥_python – 为什么“c.execute(…)”打破循环?
查看>>
python中exit和break区别_Python中exit()和sys.exit()之间的区别
查看>>
python中h5的用法
查看>>
python中http协议编程_HTTP编程
查看>>
python中if的效率_python中关于if-else使用性能的一点感悟
查看>>
python中import os_Python:相对导入与绝对导入(import)、os.path、__file__
查看>>
python中is和==操作符
查看>>
python中range()函数的返回值是多少?
查看>>
Python中range对象的使用以及打印九九乘法表
查看>>
Python中reshape函数参数-1的意思?
查看>>
Python中set.discard和set.remove方法之间的运行时差异?
查看>>
Python接口自动化测试企业级实战
查看>>
python中tkinter中value_输入字段中的python Tkinter get()值
查看>>
Python中wx.FlexGridSizer
查看>>
Python中xPath技术和BeautifulSoup的使用
查看>>
python中yield的用法详解——最简单,最清晰的解释
查看>>
python中‘set.intersection()‘的算法是什么?
查看>>