簡體   English   中英

如何將登錄限制為 3 次嘗試?

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM