[英]How to limit login to 3 attempts?
代碼:
counter = 1
pg3_txtbox_username = Entry(page3, borderwidth=0, width=16, font=('Arial',30))
pg3_txtbox_username.place(x=116, y=256, height=92)
pg3_txtbox_pass = Entry(page3, borderwidth=0, width=16, font=('Arial', 30), show='*')
pg3_txtbox_pass.place(x=116, y=422, height=90)
def verify():
conn = sqlite3.connect("data/data.db")
cursor = conn.cursor()
global counter
counter = 1
uname = pg3_txtbox_username.get()
pwd = pg3_txtbox_pass.get()
adm = "Admin"
state = "On"
if uname=='' or pwd=='':
messagebox.showinfo("Error", "Please Fill The Empty Field!!")
elif counter <=3:
cursor.execute("SELECT * FROM faculty_data WHERE Username = '" + str(uname) + "' AND Password = '" + str(pwd) + "' AND Position = '" + str(adm) + "' AND Status ='" + str(state) + "'")
if cursor.fetchone():
show_frame(page4)
messagebox.showinfo("Messgae", "WELCOME USER")
pg3_txtbox_username.delete(0, END)
pg3_txtbox_pass.delete(0, END)
check_button.deselect()
else:
counter += 1
messagebox.showinfo("Error", "Reamaining Attempt: "+ str(counter))
pg3_txtbox_username.delete(0, END)
pg3_txtbox_pass.delete(0, END)
check_button.deselect()
結果:
總是這樣的結果。 它不會增加計數器。 如果我嘗試 while 循環,它會繼續循環。 如果我刪除全局計數器下的計數器,它也會出錯。
global counter
counter = 1
錯誤:
"C:\Users\kenjo\OneDrive\Documents\PythonProject\face_recognition\face_recog.py", line 516, in verify
elif counter <=3:
NameError: name 'counter' is not defined
你有
global counter
counter = 1
每次調用verify()
時都會將counter
設置為1
。 我假設每次檢查密碼時都會調用verify()
。 因此,每次您驗證密碼時, counter
都會設置為1
並且由於您在發現密碼不正確時添加了一個……您以顯示的行為結束。
因此,您應該只刪除global
聲明正下方的counter = 1
行。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.