#版本1.0,最基本的註冊登陸
'''
1.註冊,將帳號和密碼分別寫在不一樣的文檔裏面
2.登陸,分別從帳戶文檔和密碼文檔進行讀取並登陸
'''
1 #註冊 2 Identity = input("請輸入您想要註冊的帳號:") 3 Password = input("請輸入您想要註冊的密碼:") 4 print("恭喜您註冊成功") 5 with open('id_ZC',mode='w',encoding='utf-8') as f1,open('pw_ZC',mode='w',encoding='utf-8') as f2: 6 f1.write('{}\n'.format(Identity)) 7 f2.write('{}\n'.format(Password))
1 #登陸 2 i = 0 3 ID = [] 4 PW = [] 5 while i < 1: 6 user_id = input("請輸入您的帳號:") 7 user_pw = input("請輸入您的密碼:") 8 with open('id_ZC',mode='r+',encoding='utf-8') as f1,open('pw_ZC',mode='r+',encoding='utf-8') as f2: 9 for line in f1: 10 ID.append(line) 11 #print(ID) 12 for line in f2: 13 PW.append(line) 14 #print(PW) 15 #print(ID[0].strip() == ID[0]) #ID[0]後面有換行符須要去掉 16 17 if user_id == ID[0].strip() and user_pw == PW[0].strip(): 18 print("恭喜您登陸成功!") 19 else:print("對不起,登陸失敗!") 20 i+=1