"""
1.注册
2.登录
============
1
输入账号:abc --->要求:已经注册过的不难再注册
输入密码:123456
(提示注册成功/失败)
=============
2
输入账号:abc
输入密码:123456 --->失败:1)账号没有没有注册2)密码和注册的密码不一样
"""
import json
def denglu():
n1 = input('请输入账号:')
n2 = input('请输入密码:')
for i in list1:
if i['username'] == n1 and i['password'] == n2:
print('登录成功')
break
else:
print("输入的账号密码有误")
def zhuce():
#global list1
n1 = input('请输入要注册的账号:')
for i in list1:
if i['username'] == n1:
print("账号已注册")
return zhuce()
n2 = input('请输入要注册的密码:')
list1.append({'username': n1, 'password': n2})
with open('./data.json', 'w', encoding='utf-8') as f:
list1 = json.dumps(list1)
f.write(list1)
print("注册成功")
while True:
with open('./data.json', 'r', encoding='utf-8') as f:
# result = json.loads('"abc"', encoding='utf-8')
list1 = json.loads(f.read(), encoding='utf-8')
print('1.登录:\n2.注册')
n = int(input("请选择:"))
if n == 1:
denglu()
if n == 2:
zhuce()