class Phonebook: def __init__(self): self.database = Database("phonebook_database.db") self.database.create_table("phonebook", "(first_name, last_name, phone_number)") def print(self): self.database.print_table("phonebook") print() def add_entry(self): print("please enter your first name") first_name = input() print() print("please enter your last name") last_name = input() print() print("please enter your phone number") phone_number = input() print() self.database.add_record("phonebook", 3, [(first_name, last_name, phone_number)]) print("successfully created \n") def delete_entry(self): while True: print("Please enter the first name of the entry that you want to delete. Type exit to leave.\n") entry_to_delete = input() if self.database.check_exists("phonebook", entry_to_delete): self.database.delete_record("phonebook", "first_name", entry_to_delete) print("successfully deleted \n") break elif entry_to_delete == "exit": print() break else: print("that entry does not exist \n") def close(self): self.database.close()
user_info = user_login_database.check_exists("user_data_table", input()) print(user_info) if user_info: print("Please enter your password.") if input() == user_info[1]: print("Success!") else: print("incorrect password") else: print( "This username does not exist. Would you like to create a new account? [yes, no]" ) while True: create = input() if create in ["yes", "Yes"]: print("Please enter a new username.") new_username = input() print("Please enter a new password.") new_password = input() user_login_database.add_record("user_data_table", 2, [(new_username, new_password)]) break elif create in ["no", "No"]: break else: print("please type yes or no") user_login_database.close()
class UserLogin: def __init__(self): self.screen = tkinter.Tk() self.screen.title("User Login") self.screen.geometry("300x150") self.username_label = tkinter.Label(self.screen, text="Username:"******"Password:"******"Login", command=self.login) self.create_account_button = tkinter.Button( self.screen, text="Create New Account", command=self.create_account) self.sign_up_button = tkinter.Button(self.screen, text="Sign Up", command=self.sign_up) self.username_label.grid(row=0, column=0) self.username_entry.grid(row=0, column=1) self.password_label.grid(row=1, column=0) self.password_entry.grid(row=1, column=1) self.login_button.grid(row=2, column=1) self.create_account_button.grid(row=3, column=1) # creates database self.user_login_database = Database("user_login_database.db") # creates table in user_login_database self.user_login_database.create_table("user_data_table", "(username, password)") self.user_login_database.print_table("user_data_table") def login(self): self.username = self.username_entry.get() self.password = self.password_entry.get() self.user_info = self.user_login_database.check_exists( "user_data_table", self.username) if self.user_info: if self.password in self.user_info: tkinter.messagebox.showinfo(message="Success!") self.username_entry.delete(0, tkinter.END) self.password_entry.delete(0, tkinter.END) else: tkinter.messagebox.showwarning(message="Incorrect password.") self.password_entry.delete(0, tkinter.END) else: tkinter.messagebox.showwarning(message="Username does not exist.") def create_account(self): self.login_button.grid_forget() self.create_account_button.grid_forget() self.sign_up_button.grid(row=2, column=1) def sign_up(self): self.username = self.username_entry.get() self.password = self.password_entry.get() self.username_entry.delete(0, tkinter.END) self.password_entry.delete(0, tkinter.END) self.user_login_database.add_record("user_data_table", 2, [(self.username, self.password)]) self.sign_up_button.grid_forget() self.login_button.grid(row=2, column=1) self.create_account_button.grid(row=3, column=1) def run(self): self.screen.mainloop()