Group 4
Group 4
• Import tkinter as tk
• accounts = {}
def set_focus():
• username_entry.focus_set()
z
• Def create_account():
z
• username = username_entry.get()
• password = password_entry.get()
• if username in accounts:
• questions = [
• “What is your favorite sport?”,
• “What is your pet’s name?”,
• “What city were you born in?” ]
• question_selection =
• simpledialog.askstring(“Select Security Question”,
• f”Choose a security
• question:\n1. {questions[0]}\n2.
• {questions[1]}\n3.
• {questions[2]}\n\nEnter 1, 2, or 3:”)
z
z
• If question_selection in [‘1’, ‘2’, ‘3’]:
• question_index = int(question_selection) – 1
• answer = simpledialog.askstring(“Answer Security Question”,
• questions[question_index])
• if answer:
• accounts[username] = {
• ‘password’: password,
• ‘security_question’:
• questions[question_index],
• ‘security_answer’:
• answer
• }
z
• Messagebox.showinfo(“Account Created”, f”Account created
successfully for {username}!”)
• username_entry.delete(0, tk.END)
• password_entry.delete(0, tk.END)
• else: messagebox.showerror(“Account Creation
Failed”, “Please answer the security question.”)
• else:
• messagebox.showerror(“Error”, “Invalid selection. Please
enter 1, 2, or 3.”)
z
• username = simpledialog.askstring(“Forgot
Password”, “Enter your username:”)
• if username not in accounts:
• messagebox.showerror(“Error”, “Username not
found.”)
• return
• question = accounts[username][‘security_question’]
• answer = simpledialog.askstring(“Answer Security
Question”, question)
z
z
• If answer:
• stored_answer = accounts[username][‘security_answer’]
• if answer == stored_answer:
• new_password = simpledialog.askstring(“Reset
• Password”, “Enter your new
• password:”, show=“*”)
• if new_password accounts[username][‘password’] =
• new_password messagebox.showinfo(“Success”, “Password
reset successfully!”)
• else:
• messagebox.showerror(“Error”, “No password entered.”)
• else:
• messagebox.showerror(“Error”, “Incorrect answer to the
security question.”)
z
• Def verify_password():
z
• username = username_entry.get()
• password = password_entry.get()
• if username in accounts and accounts[username][‘password’] ==
password:
• messagebox.showinfo(“Login Successful”, f”Welcome
{username}!”)
• else:
• messagebox.showerror(“Login Failed”, “Invalid username or
password.”)
def enter_pressed(event):
if event.widget == username_entry:
password_entry.focus_set()
elif event.widget ==
• password_entry:
• verify_password()
• Rootz= tk.Tk()
root.title(“Pulung Santol Sports Portal”)
root.geometry(“300x300”)
root.config(bg=“#cceeff”)
username_label = tk.Label(credentials_frame,
text=“Username:”, font=(“Arial”, 10), bg=“#cceeff”)
username_label.grid(row=0, column=0, padx=5,
sticky=“w”)
username_entry = tk.Entry(credentials_frame,
font=(“Arial”, 10), width=15)
username_entry.grid(row=0, column=1, padx=5)
z
• Password_label = tk.Label(credentials_frame,
text=“Password:”, font=(“Arial”, 10),
bg=“#cceeff”)
password_label.grid(row=1, column=0, padx=5,
sticky=“w”)
password_entry = tk.Entry(credentials_frame,
font=(“Arial”, 10), show=“*”, width=15)
password_entry.grid(row=1, column=1, padx=5)
• Username_entry.bind(‘<Return>’,
z
enter_pressed)
password_entry.bind(‘<Return>’, enter_pressed)
login_button = tk.Button(credentials_frame,
text=“Login”, font=(“Arial”, 10),
command=verify_password)
login_button.grid(row=1, column=2, padx=5)
forgot_password_button = tk.Button(button_frame,
text=“Forgot Password”, font=(“Arial”, 10),
command=forgot_password)
forgot_password_button.grid(row=0, column=1, padx=10)
z
• Set_focus()
root.mainloop()
submitted to:
AVEC
MALLARI