python 多使用者登入

來源:互聯網
上載者:User

標籤:使用者名稱   後退   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             break
View Code

 

python 多使用者登入

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.