title: All logins are being accepted by the program, unsure as to why
body: <p>I've been experimenting with a sqlite3 for the first time and was developing a login system (with some help from articles and videos) and have noticed that all credentials inputted into the program are being accepted, I can't find a fault in the program so I could use some help.</p>
  <h1>Importing Important Libraries</h1>
  <pre><code>import sqlite3
  import bcrypt
  
  
      class Database:
       
          def __init__(self):
              try:
                  self.conn = sqlite3.connect(&quot;usertable.db&quot;)
                  print(&quot;Successfully Opened Database&quot;)
                  self.curr = self.conn.cursor()
              except:
                  print(&quot;Failed&quot;)
      
          def createTable(self):
      
              create_table = '''
                  CREATE TABLE IF NOT EXISTS cred(
                      id Integer PRIMARY KEY AUTOINCREMENT,
                      username TEXT NOT NULL,
                      password TEXT NOT NULL
                  );
              '''
      
              self.curr.execute(create_table)
              self.conn.commit()
      
          def insertData(self, data):
      
              insert_data = &quot;&quot;&quot;
                  INSERT INTO cred(username, password)
                  VALUES(?, ?);
              &quot;&quot;&quot;
              
              self.curr.execute(insert_data, data)
              self.conn.commit()
      
          def searchData(self, data):
      
              search_data = '''
                  SELECT * FROM cred WHERE username = (?);
              '''
      
              self.curr.execute(search_data, data)
      
              rows = self.curr.fetchall()
      
              if rows == []:
                  return 1
              return 0
      
          def validateData(self, data, inputData):
              validate_data = &quot;&quot;&quot;
                  SELECT * FROM cred WHERE username = (?);
              &quot;&quot;&quot;
      
              self.curr.execute(validate_data, data)
              row = self.curr.fetchall()
      
              if row[0][1] == inputData[0]:
                  return row[0][2] == bcrypt.hashpw(inputData[1].encode(), row[0][2])
      
      
      
      
      (The login and register classes)
      
      
      
      from tkinter import *
      from tkinter import messagebox
      import bcrypt
      from database import Database
      
      
      db = Database()
      db.createTable()
      
      class Login:
          
          def __init__(self):
              self.loginWindow = Tk()
              self.loginWindow.title(&quot;Login&quot;)
              self.loginWindow.geometry(&quot;300x250&quot;)
              self.label = Label(self.loginWindow, text=&quot;Login&quot;)
              self.label.place(x=95, y=40)
      
              self.usernames = StringVar()
              self.passwords = StringVar()
      
              self.usernameE = Entry(self.loginWindow, relief=FLAT, textvariable=self.usernames)
              self.usernameE.place(x=70, y=80)
              self.passwordE = Entry(self.loginWindow, show=&quot;*&quot;, relief=FLAT, textvariable = self.passwords)
              self.passwordE.place(x=70, y=120)
              
              self.username = self.usernames.get()
              self.password = self.passwords.get()
      
              self.submit = Button(self.loginWindow, text = &quot;Submit&quot;, pady = 5, padx = 20, command = self.validate)
              self.submit.place(x=100, y=150)
          
          def validate(self):
              data = (self.username,)
              inputData = (self.username, self.password,)
              try:
                  if (db.validateData(data, inputData)):
                      messagebox.showinfo(&quot;Successful&quot;, &quot;Login Was Successful&quot;)
                  else:
                      messagebox.showerror(&quot;Error&quot;, &quot;Wrong Credentials&quot;)
              except IndexError:
                  messagebox.showerror(&quot;Error&quot;, &quot;Wrong Credentials&quot;)
      
          def run(self):
              self.loginWindow.mainloop()
      
      
      
      class Register:
      
          def __init__(self):
              self.registerWindow = Tk()
              self.registerWindow.title(&quot;Register&quot;)
              self.registerWindow.geometry(&quot;300x250&quot;)
              self.label = Label(self.registerWindow, text=&quot;Register&quot;)
      
              self.usernameS = StringVar()
              self.passwordS = StringVar()
      
              self.usernameE = Entry(self.registerWindow, relief = FLAT, textvariable = self.usernameS)
              self.usernameE.place(x=70, y=80)
              self.passwordE = Entry(self.registerWindow, show=&quot;*&quot;, relief = FLAT, textvariable = self.passwordS)
              self.passwordE.place(x=70, y=120)
              self.submit = Button(self.registerWindow, text=&quot;Submit&quot;, pady = 5, padx = 20, command = self.add)
              self.submit.place(x=100, y=150)
      
              self.username = self.usernameS.get()
              self.password = self.passwordS.get()
      
              self.salt = bcrypt.gensalt()
              self.hashed = bcrypt.hashpw(self.password.encode(), self.salt)
      
          def run(self):
              self.registerWindow.mainloop()
      
          def add(self):
              data = (self.username,)
      
              result = db.searchData(data)
      
              print(result, result, result)
              
              if result != 0:
                  data = (self.username, self.hashed)
                  db.insertData(data)
                  messagebox.showinfo(&quot;Successful&quot;, &quot;Username Was Added&quot;)
              else:
                  messagebox.showwarning(&quot;Warning&quot;, &quot;Username already Exists&quot;)
      
      
      
      
      (The main window class)
      
      
      
      
      from tkinter import *
      from login import Login, Register
      
      
      class Window(object):
      
          def __init__(self):
              self.window = Tk()
              self.window.title(&quot;Login Screen&quot;)
              self.window.geometry(&quot;300x250&quot;)
              self.label = Label(self.window, text = &quot;Welcome to Login&quot;)
              self.label.place(x=95, y=40)
              self.login = Button(self.window, text = &quot;Login&quot;, pady = 5, padx = 30, command = login)
              self.login.place(x=100, y=100)
              self.register = Button(self.window, text = &quot;Register&quot;, pady = 5, padx = 20, command = register)
              self.register.place(x=100, y=150)
      
      
      
          def run(self):
              self.window.mainloop()
      
      
      def login():
          loginTk = Login()
          loginTk.run()
      
      def register():
          registerTk = Register()
          registerTk.run()
      
      
      window = Window()
      window.run()
  </code></pre>
  <p>The program is stored in 3 different files (the login and register classes are stored within the same file.)</p>