# 注册登录系统 import hashlib import json import os # 账户新是一个保存在文件中字典 def load_account(path): if os.path.exists(path): return json.load(open(path, "rt", encoding="utf-8")) else: return {} # 将用户信息字典保存到硬盘中 def save_account(account_info, path): json.dump(account_info, open(path, "at", encoding="utf-8")) UI = """ 1.注册 2.登陆 0.退出 """ while True: input("请输入回车继续.......") print(UI) select = int(input("请输入你的选择:")) if select == 1: pass # 注册 # 用输入账户密码,确认密码 account = input("请输入账户:") dc = load_account("account.txt") if dc.get(account): print("该账户已存在,请重新注册") else: passwort = input("请输入密码:") confirm = input("请再次输入密码:") if passwort == confirm: # 密码加密 hs_obj = hashlib.md5(passwort.encode()) dc[account] = hs_obj.hexdigest() save_account(dc, "account.txt") else: print("前后两次密码输入不一致") elif select == 2: acc=input("请输入账户") pwd = load_account("account.txt") dc=load_account("account.txt") if dc.get(acc): hs_obj=hashlib.md5(pwd.encode()) pwd_encrypt=hs_obj.hexdigest() if pwd_encrypt==dc[acc]: print("登录成功") else: print("登录失败") else: print("登陆失败") elif select==0: sys.exit()
10-14
2703
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
05-10
4010
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)