Python實(shí)現(xiàn)賬號密碼輸錯三次即鎖定功能簡單示例
本文實(shí)例講述了Python實(shí)現(xiàn)賬號密碼輸錯三次即鎖定功能。分享給大家供大家參考,具體如下:
初學(xué)Python—1
#實(shí)現(xiàn)賬號輸錯三次即鎖定
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("賬戶已經(jīng)鎖定!")
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()
基本功能可以實(shí)現(xiàn);
鎖定的賬號為第三次輸錯的用戶名(待完善)
以下為完善版本,如有錯誤,請告知
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("賬戶已經(jīng)鎖定!")
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("密碼輸入錯誤超過三次,賬戶已經(jīng)鎖定!")
fileOpen.seek(0)
continue
else:
print("賬號密碼錯誤!")
continue
check=input("還想驗(yàn)證其他賬戶?(yes-繼續(xù),no-退出)")
if "no"==check.lower():
os._exit(0)
else:
continue
fileOpen.close()
更多關(guān)于Python相關(guān)內(nèi)容感興趣的讀者可查看本站專題:《Python數(shù)據(jù)結(jié)構(gòu)與算法教程》、《Python編碼操作技巧總結(jié)》、《Python函數(shù)使用技巧總結(jié)》、《Python字符串操作技巧匯總》及《Python入門與進(jìn)階經(jīng)典教程》
希望本文所述對大家Python程序設(shè)計(jì)有所幫助。
相關(guān)文章
python實(shí)現(xiàn)一組典型數(shù)據(jù)格式轉(zhuǎn)換
這篇文章主要為大家詳細(xì)介紹了python實(shí)現(xiàn)一組典型數(shù)據(jù)格式轉(zhuǎn)換,具有一定的參考價值,感興趣的小伙伴們可以參考一下2018-12-12
Python使用微信SDK實(shí)現(xiàn)的微信支付功能示例
這篇文章主要介紹了Python使用微信SDK實(shí)現(xiàn)的微信支付功能,結(jié)合實(shí)例形式分析了Python調(diào)用微信SDK接口實(shí)現(xiàn)微信支付功能的具體步驟與相關(guān)操作技巧,需要的朋友可以參考下2017-06-06
Python和C語言利用棧分別實(shí)現(xiàn)進(jìn)制轉(zhuǎn)換
這篇文章主要為大家詳細(xì)介紹了Python和C語言如何利用棧的數(shù)據(jù)結(jié)構(gòu)分別實(shí)現(xiàn)將十進(jìn)制數(shù)轉(zhuǎn)換成二進(jìn)制數(shù),文中的示例代碼講解詳細(xì),需要的可以參考一下2022-07-07
Python數(shù)據(jù)結(jié)構(gòu)之圖的應(yīng)用示例
這篇文章主要介紹了Python數(shù)據(jù)結(jié)構(gòu)之圖的應(yīng)用,結(jié)合實(shí)例形式分析了Python數(shù)據(jù)結(jié)構(gòu)中圖的定義與遍歷算法相關(guān)操作技巧,需要的朋友可以參考下2018-05-05
python PaddleSpeech實(shí)現(xiàn)嬰兒啼哭識別
這篇文章主要為大家介紹了python PaddleSpeech實(shí)現(xiàn)嬰兒啼哭識別操作詳解,有需要的朋友可以借鑒參考下,希望能夠有所幫助,祝大家多多進(jìn)步,早日升職加薪2022-08-08
如何解決jupyter notebook無法導(dǎo)入自己安裝的包
這篇文章主要介紹了如何解決jupyter notebook無法導(dǎo)入自己安裝的包問題,具有很好的參考價值,希望對大家有所幫助。如有錯誤或未考慮完全的地方,望不吝賜教2023-07-07

