python密碼錯誤三次鎖定,python密碼錯誤鎖定

來源:互聯網
上載者:User

python密碼錯誤三次鎖定,python密碼錯誤鎖定

程式需求:

流程圖:

  好像畫的不咋地

查看代碼:

#!/usr/bin/env python# _*_ coding:utf-8 _*_# File_type:一個登入介面# Author:smelondimport osusername = "smelond"#使用者名稱password = "qweqwe"#密碼counter = 0#計數器#讀取黑名單file = os.path.exists("./user.txt")#檢查目前的目錄是否有user.txt這個檔案,如果有者輸出True賦給fileif file == True:#判斷是否有user.txt這個檔案    blacklist_file = open("user.txt", "r").read()#open()開啟檔案,並且用read()讀取檔案,然後賦給blacklist_file    if blacklist_file == username:#檢查檔案裡面的內容是否和我們的使用者名稱相等        print("Username lock. Please contact the administrator to remove the restrictions!!!")#輸出錯誤提示        exit()#退出程式#登入介面for i in range(3):    counter += 1#對每次登入進行計數    input_user = input("Please input username: ")    input_pass = input("Please input password: ")    if input_user == username and input_pass == password:        print("Welcome login...")        break    else:        print("ERROR Incorrect username or password!!!")        continue#寫入黑名單if counter == 3:#判斷我是否輸入錯誤三次    print("The user name has been disabled")#提示資訊    blacklist_user = open("user.txt", "a")#以追加模式開啟 (從 EOF 開始, 必要時建立新檔案)    blacklist_user.write("%s" % username)#將使用者名稱寫入黑名單    blacklist_user.close()#使用open後一定要記得調用檔案對象的close()方法
代碼

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.