標籤:使用者名稱 後退 use else nes code pytho ide blacklist
Python多使用者登入
需求
- 讓使用者輸入使用者名稱密碼
- 認證成功後顯示歡迎資訊
- 輸錯三次後退出程式
- 可以支援多個使用者登入 (提示,通過列表存多個賬戶資訊)
- 使用者3次認證失敗後,退出程式,再次啟動程式嘗試登入時,還是鎖定狀態(提示:需把使用者鎖定的狀態存到檔案裡)
流程圖
代碼
1 #! /usr/bin/env python 2 # -*- coding: utf-8 -*- 3 #多使用者登入 4 5 user_list={ 6 ‘u01‘:{‘password‘:‘123‘}, 7 ‘u02‘:{‘password‘:‘123‘}, 8 ‘u03‘:{‘password‘:‘123‘}, 9 }10 f = open(‘blacklist.txt‘,‘r‘)11 lock_file = f.readlines()12 f.close()13 count=014 while True:15 if count == 3:16 print("使用者名稱輸入次數到達3次限制")17 break18 user_name=input("請輸入您的使用者名稱>>:")19 if user_name not in user_list:20 print("使用者名稱錯誤")21 count+=122 if user_name in lock_file:23 print("使用者名稱鎖定,請聯絡管理員!")24 exit()25 if user_name in user_list:26 # count-=227 user_password=input("請輸入您的密碼>>: ")28 if user_password == user_list[user_name][‘password‘]:29 print("歡迎登入")30 break31 else:32 print("密碼錯誤")33 count += 134 if count == 3 :35 print("您輸入的密碼錯誤次數已達3次,將鎖定您的使用者!")36 f = open(‘blacklist.txt‘,‘w‘)37 f.write(‘%s‘%user_name)38 f.close()39 breakView Code
python 多使用者登入