-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
126 lines (98 loc) · 4.82 KB
/
main.py
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
117
118
119
120
121
122
123
import tkinter as tk
import os
from tkinter import messagebox
import cv2
# Create a new Tkinter window
window = tk.Tk()
window.title("M-Pass Login")
window.geometry("400x300")
window.minsize(800, 600)
window.maxsize(1200, 900)
# Set a custom background color for the window
window.config(bg="#cce6ff")
# Create a label for the title
title_label = tk.Label(text="Welcome to M-Pass", font=("Arial", 24), fg="#333333", bg="#F0F0F0")
title_label.pack(pady=20)
# Create a frame for the username and password fields
input_frame = tk.Frame(window, bg="#F0F0F0")
input_frame.pack()
# Create a label and entry box for the username
username_label = tk.Label(input_frame, text="Username:", font=("Arial", 14), fg="#333333", bg="#F0F0F0")
username_label.grid(row=0, column=0, padx=10, pady=10, sticky="w")
username_entry = tk.Entry(input_frame, font=("Arial", 14))
username_entry.grid(row=0, column=1, padx=10, pady=10)
# Create a label and entry box for the master password
password_label = tk.Label(input_frame, text="Master Password:", font=("Arial", 14), fg="#333333", bg="#F0F0F0")
password_label.grid(row=1, column=0, padx=10, pady=10, sticky="w")
password_entry = tk.Entry(input_frame, show="*", font=("Arial", 14))
password_entry.grid(row=1, column=1, padx=10, pady=10)
# Set variables to keep track of the number of login attempts and whether a photo has been taken
login_attempts = 0
photo_taken = False
# Create a button to log in
def login():
# Declare the global variables for login attempts and photo taken
global login_attempts, photo_taken
# Check if the username and password are valid
if username_entry.get() == "sudo" and password_entry.get() == "1YjrI135#":
# Display a message box
messagebox.showinfo("Login", "Login successful!")
# Reset the login attempts counter and photo taken flag
login_attempts = 0
photo_taken = False
# Open the landing page using the os module
os.system('python home.py')
# Close the current window
window.destroy()
else:
# Increment the login attempts counter
login_attempts += 1
# Display an error message if the password is incorrect
messagebox.showerror("Error", "Invalid username or password")
# Check if the user has entered the correct password
if password_entry.get() == "1YjrI135#":
# Check if the user has entered the wrong password more than once
if login_attempts >= 2:
# Show a warning message about unauthorized access attempts
response = messagebox.askokcancel("Warning",
"Unauthorized access attempt detected! Do you want to view the login attempts log?")
if response == 1:
# Open the login attempts log using the os module
os.system('python log.py')
# Check if the user has entered the wrong password more than twice
if login_attempts >= 3:
# Take a photo using the webcam
if not photo_taken:
# Create a VideoCapture object
cap = cv2.VideoCapture(0)
# Check if the webcam is available
if not cap.isOpened():
messagebox.showerror("Error", "Webcam is not available!")
else:
# Capture a photo
ret, frame = cap.read()
if ret:
# Save the photo as a JPEG file
cv2.imwrite("unauthorized_access.jpg", frame)
# Display a message box
messagebox.showwarning("Warning", "Unauthorized access attempt detected! A photo has been taken and saved.")
# Set the photo_taken flag to True
photo_taken = True
# Release the webcam
cap.release()
if username_entry.get() == "sudo" and password_entry.get() == "1YjrI135#":
response = messagebox.askokcancel("Warning",
"Unauthorized access attempt detected! Do you want to view the login attempts log?")
if response == 1:
# Open the login attempts log using the os module
os.system('python log.py')
login_button = tk.Button(window, text="Log In", command=login, font=("Arial", 14), bg="#333333", fg="#F0F0F0")
login_button.pack(pady=10)
# Create a button to sign up
def signup():
# Display a message box with instructions for signing up
messagebox.showinfo("Sign Up", "To sign up, please contact the administrator.")
signup_button = tk.Button(window, text="Sign Up", command=signup, font=("Arial", 14), bg="#333333", fg="#F0F0F0")
signup_button.pack()
# Start the Tkinter event loop
window.mainloop()