模擬登陸

模擬登錄:
1. 用戶輸入賬號密碼進行登錄
2. 用戶信息保存在文件內
3. 用戶密碼輸入錯誤三次後鎖定用戶app

方法一 (分別輸入姓名和密碼)spa

 1 #帳號和密碼
 2 name = 'nikita'
 3 password = '123'
 4 count = 0
 5 #讀取黑名單
 6 f = open('black_list.txt','r')
 7 black = f.read()
 8 f.close()
 9 ls = []
10 #三次登陸信息
11 T = True
12 while T:
13     name1 = input('Please enter name:')
14     #檢查name1是否在black_list
15 
16     if name1 in black:
17         print ('Sorry, you cannt login')
18         break
19     #不在black_list
20     else:
21         password1 = input("Please enter password:")
22         if name == name1 and password == password1:
23             print ('Welcome!')
24             break
25 
26         else:
27             print ('Your name and password are wrong')
28             ls.append(name1)
29             x = ls.count(name1) #輸入的名字放入list裏,當相同名字輸入三次,鎖定帳號
30             if x>=3:
31                 T = False
32                 print('Your account is locked.')
33                 f = open('black_list.txt','a')
34                 f.write(name1 + '\n')
35                 f.close()
36                 break

方法二(先輸入名字,在輸入屢次密碼)code

 1 #帳號和密碼
 2 name = 'nikita'
 3 password = '123'
 4 count = 0
 5 #讀取黑名單
 6 f = open('black_list.txt','r')
 7 black = f.read()
 8 f.close()
 9 #三次登陸信息
10 name1 = input('Please enter name:')
11 #檢查name1是否在black_list
12 if name1 in black:
13     print ('Sorry, you cannt login')
14 #不在black_list
15 else:
16     for i in range(3):
17         password1 = input("Please enter password:")
18         if name == name1 and password == password1:
19             print ('Welcome!')
20 
21         else:
22             print ('Your password is wrong')
23             count+=1
24 #登陸三次鎖定帳號
25         if count == 3:
26             print ('Your account is locked.')
27             f = open('black_list.txt','a')
28             f.write(name1+'\n')
29             f.close()
相關文章
相關標籤/搜索