python 多用戶登錄


需求:

  • 可以支持多個用戶登錄 (提示,通過列表存多個賬戶信息)
  • 用戶3次認證失敗后,退出程序,再次啟動程序嘗試登錄時,還是鎖定狀態(提示:需把用戶鎖定的狀態存到文件里)

流程圖:

代碼:

 1 div={
 2 'list1':{'password':'123456'},
 3 'list2':{'password':'123456'},
 4 'list3':{'password':'123456'},
 5 }
 6 f = open('black_user','r')
 7 lock_file = f.readlines()
 8 f.close()
 9 count=0
10 count1=0
11 while True:
12     name_input=input("please input name:")
13     if count == 3:
14         print("用戶名輸入次數到達限制")
15         break
16     if  not name_input in div:
17             print("用戶名錯誤")
18             count +=1
19     if  name_input in lock_file:
20         print("戶名已鎖定,暫停使用!")
21         exit()
22 
23     if name_input in div:
24         count -=2
25         password_input=str(input("please input password:"))
26         if password_input == div[name_input]['password']:
27             print ("密碼成功")
28             break
29         else:
30             print("密碼錯誤")
31             count1 +=1
32         if count1 == 2:
33             print("您輸入的密碼錯誤次數已達3次,將鎖定您的賬戶!")
34             f = open('black_user', 'w')
35             f.write('%s'%name_input)
36             f.close()
37             break

 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM