mardi 15 août 2017

Could someone please help me with my bug in my login screen?

I currently have a bug whereby it seems that not all the users in the sqlite3 database are iterated through. I doubt that it is the iteration that is the problem, but I can't seem to understand what is causing my program to keep returning to me the fact that "The details entered are the wrong username and wrong password".

I have initialised some variables as the following:

self.currentUsername = ""
self.currentPassword = ""
self.press = 5
self.position = 0
self.list_of_users = ""
self.user = ""

Later on in the code I utilise this method to sift through the database and decide whether the user can enter the main part of the application or not.

    def LoginCheck(self):
    # global press
    # global currentUsername
    # global currentPassword
    if self.press >= 1:

        c.execute("SELECT * FROM Users")
        self.list_of_users = (c.fetchall())
        print(self.list_of_users) # Uncomment to print everything in the 
user table as a list
        self.position = 0
        for _ in self.list_of_users:
            self.user = self.list_of_users[self.position]
            if self.userEnt.get() == self.user[3] and self.passEnt.get() == 
self.user[4]:
                print("Welcome,", self.user[1])
                print("ID:", self.user[0])
                print("First Name:", self.user[1])
                print("Last Name:", self.user[2])
                print("User Name:", self.user[3])
                self.currentUsername = self.user[3]
                print("Password:", self.user[4])
                self.currentPassword = self.user[4]
                start.destroy()
# ----------------------------------------------------------------------------------------------------------------------
                app = Application()
                app.state("zoomed")
                app.resizable(False, False)
                app.mainloop()
# ----------------------------------------------------------------------------------------------------------------------
            elif self.userEnt.get() != self.user[3] and self.passEnt.get() 
!= self.user[4]:
                self.userEnt.delete(0, "end")
                self.userEnt.insert(0, "The details entered are the wrong 
username and wrong password")
                print(self.position)
                print(self.press)
            elif self.userEnt.get() != self.user[3] and self.passEnt.get() 
== self.user[4]:
                print("Incorrect username")
                print(self.user)
                print(str(self.press - 1)+" tries left")
                self.userEnt.delete(0, "end")
                self.userEnt.insert(0, "Enter the correct username please. " 
+ str(self.press - 1) + "/" + str(5) +
                                    " tries left")
                print(self.position)
                print(self.press)
                self.press -= 1
            elif self.userEnt.get() == self.user[3] and self.passEnt.get() 
!= self.user[4]:
                print("Incorrect password")
                print(self.user)
                print(str(self.press - 1)+" tries left")
                self.userEnt.delete(0, "end")
                self.userEnt.insert(0, "Enter the correct password please. " 
+ str(self.press - 1) + "/" + str(5) +
                                    " tries left")
                print(self.position)
                print(self.press)
                self.press -= 1
            else:
                self.position += 1

    if self.press == 1:
        self.userEnt.delete(0, "END")
        self.userEnt.insert(0, "One attempt left. A 20 second ban is 
imminent.")
    if self.press == 0:
        self.userEnt.state = "readonly"
        self.passEnt.state = "readonly"
        time.sleep(20)
        self.press = 5
        self.userEnt.state = "ENABLED"
        self.passEnt.state = "ENABLED"
        self.userEnt.delete(0, "end")
        self.userEnt.insert(0, "Username")

I know this is long-winded but it is necessary that I move on to building the next part of my application. Your help is very much appreciated :)

Aucun commentaire:

Enregistrer un commentaire