-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathcheck_seq_question.py
More file actions
116 lines (89 loc) · 4.35 KB
/
Copy pathcheck_seq_question.py
File metadata and controls
116 lines (89 loc) · 4.35 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
import json
import tkinter
from tkinter import messagebox
import customtkinter
from customtkinter import *
import mysql.connector
import connection
from change_password import Change_password
colors = ["#070F2B", "#1B1A55", "#535C91"]
fonts = 'Century Gothic'
class Security_questions(customtkinter.CTk):
def __init__(self):
super().__init__()
self.title("SECURITY QUESTIONS")
self.config(bg=colors[0])
self.geometry("600x400+550+220")
self.load_questions()
def load_questions(self):
try:
with open("question.json", "r") as file:
data = json.load(file)
self.questions = data["questions"]
self.create_question_widgets()
except FileNotFoundError:
print("Error: questions.json file not found.")
def create_question_widgets(self):
self.answers = {}
self.check_label = CTkLabel(master=self, text="FILL SECURITY QUESTIONS FOR YOUR VERIFICATION",
font=(fonts, 18), bg_color=colors[0])
self.check_label.place(x=50, y=10)
self.frame = CTkFrame(master=self, width=1200, height=580, fg_color=colors[2], corner_radius=16,
border_color="#3E065F", bg_color=colors[0])
self.frame.place(relx=0.5, rely=0.5, anchor=tkinter.CENTER)
for i, question_data in enumerate(self.questions):
question_label = CTkLabel(master=self.frame, text=question_data["question"], font=(fonts, 12),
wraplength=500)
question_label.grid(row=i, column=0, padx=10, pady=10, sticky="w")
answer_entry = CTkEntry(master=self.frame, font=(fonts, 12))
answer_entry.grid(row=i, column=1, padx=10, pady=10, sticky="w")
self.answers[question_data["id"]] = answer_entry
self.Accno_label = CTkLabel(master=self.frame, text="Account number: ")
self.Accno_label.place(x=100, y=150)
self.Accno = CTkEntry(master=self.frame, width=150, placeholder_text="Enter Account number", fg_color="#424769")
self.Accno.place(x=230, y=150)
self.submit_button = CTkButton(master=self.frame, text="Submit", font=(fonts, 12), command=self.submit_answers)
self.submit_button.grid(row=len(self.questions), columnspan=2, pady=40)
def submit_answers(self):
account_number = self.Accno.get()
user_answers = {}
all_answers_filled = all(answer_entry.get() for answer_entry in self.answers.values())
if not all_answers_filled:
messagebox.showerror("Error", "Please answer all three security questions.")
return
elif not account_number:
messagebox.showerror("Error", "Enter Your account number")
return
try:
account_number = int(account_number)
print(account_number)
except ValueError:
messagebox.showerror("Error", "Account Number should be a number")
return
for question_id, answer_entry in self.answers.items():
user_answers[question_id] = answer_entry.get()
print("User Answers:", user_answers)
try:
db = connection.Connection().get_connection()
cursor = db.cursor()
cursor.execute("SELECT user_answer FROM answer WHERE id = %s", (account_number,))
result = cursor.fetchone()
if result is None:
messagebox.showerror("Error", "Invalid Credentials")
else:
stored_answers = json.loads(result[0])
# Convert keys of user_answers to strings
user_answers_str_keys = {str(key): value for key, value in user_answers.items()}
if stored_answers == user_answers_str_keys:
print("User answers match the stored answers.")
self.destroy()
change_password_page = Change_password(account_number=account_number)
change_password_page.mainloop()
else:
messagebox.showerror("Error", "User answers do not match the stored answers.")
print("User answers do not match the stored answers.")
except mysql.connector.Error as err:
print("Error:", err)
if __name__ == '__main__':
App = Security_questions()
App.mainloop()