Implement user login register

import json
def login(acc_data):
count = 0
user = input("account:")
passwd = input("password:")
while count < 3:
with open("database", "r") as db:
d = json.loads(db.read())
if user == d.get("username") and passwd == d.get("password"):
print("login successfully")
break
else:
print("Incorrect user name or password")
count += 1


def regist(acc_data):
user = input("usrname>>>")
passwd = input("password>>>")
temp = {

"username" : user,
"password" : passwd,
}
data = json.dumps(temp)
with open("database","a") as db:

db.write(data+"\n")



def start(acc_data):

menu = """
"1>>>登录",
"2>>>注册",
"3>>>退出"
"""

menu_dict = {
"1": login,
"2": regist,

}
exit_flag = False
while not exit_flag:
print(menu)
user_option = input(">>:").strip()
if user_option in menu_dict:
menu_dict[user_option](acc_data)
elif user_option == "3":
print("Welcome to again")
break

start(1)

Guess you like

Origin www.cnblogs.com/langjitanya/p/10961139.html