您好,登錄后才能下訂單哦!
本文實例講述了Python實現賬號密碼輸錯三次即鎖定功能。分享給大家供大家參考,具體如下:
初學Python—1
#實現賬號輸錯三次即鎖定 user = "hubery" passwd = "123" confirm = 0 lock=0 fileOpen = open("username.txt","a+") fileOpen.seek(0) for i in range(3): username = input("username:") passsword = input("password:") for line in fileOpen.readlines(): if username == line.strip(): print("賬戶已經鎖定!") lock=1 break else: continue fileOpen.seek(0) if user == username and lock ==0: if passwd == passsword: print("歡迎,歡迎!") confirm = 1 break else: print("賬號戶或者密碼錯誤!") continue elif lock==1: continue else: print("1賬號或者密碼錯誤!") continue fileOpen.close() if confirm == 0 and lock==0: fileWrite=open("username.txt","a") fileWrite.write(username+"\n") fileWrite.close()
基本功能可以實現;
鎖定的賬號為第三次輸錯的用戶名(待完善)
以下為完善版本,如有錯誤,請告知
import os user = "hubery" passwd = "123" count = 0 lock = 0 fileOpen = open("username.txt", "a+") fileOpen.seek(0) while 1: for i in range(5): username = input("username:") passsword = input("password:") for line in fileOpen.readlines(): if username == line.strip(): print("賬戶已經鎖定!") lock = 1 break else: continue fileOpen.seek(0) if user == username: if lock == 1: continue elif passsword == passwd: print("歡迎,歡迎!") os._exit(0) elif count < 2: print("賬號或者密碼錯誤!") count += 1 continue else: fileOpen.write(username + "\n") fileOpen.flush() print("密碼輸入錯誤超過三次,賬戶已經鎖定!") fileOpen.seek(0) continue else: print("賬號密碼錯誤!") continue check=input("還想驗證其他賬戶?(yes-繼續,no-退出)") if "no"==check.lower(): os._exit(0) else: continue fileOpen.close()
更多關于Python相關內容感興趣的讀者可查看本站專題:《Python數據結構與算法教程》、《Python編碼操作技巧總結》、《Python函數使用技巧總結》、《Python字符串操作技巧匯總》及《Python入門與進階經典教程》
希望本文所述對大家Python程序設計有所幫助。
免責聲明:本站發布的內容(圖片、視頻和文字)以原創、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。