信息表1.txt
username,password,age,position,department,phone alex,abc123,30,Engineer,IT,13651830433 rain,df2@432,25,Teacher,Teaching,18912334223 黑姑娘,df2@432,26,行政,人事,13811177306
代码实现
def login(): loginSucess = False with open("1.txt", "r", encoding="utf-8") as f: line = f.readlines() while True: username = input("请输入用户名:").strip() if len(username) != 0: #判断用户名不为空 for i in line: i = i.split(",") # print(i) if username == i[0]: # 用户名输入正确 for x in range(3): password = input("请输入密码:").strip() if password == i[1]: #密码正确 loginSucess = True break else: print("密码输错三次,请重新输入密码") break if loginSucess is True: print(f"welcome {i[0]}".center(50, '-')) break elif loginSucess is False: print("用户名输入错误,请重新输入:") else: break else: continue login()