-
Notifications
You must be signed in to change notification settings - Fork 0
/
login.py
191 lines (165 loc) · 8.55 KB
/
login.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
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
# Importing Libraries
from tkinter import *
from tkinter import messagebox as ms
import tkinter as tk
import sqlite3
from tkinter import filedialog
from PIL import ImageTk, Image
from Encryptor import Encryptor
def Log():
# Creating a new window
Login = tk.Tk()
Login.geometry('500x500')
Login.title('Login to System !')
# Background Colors
Login.configure(background='#7fb8f5')
# Locking the window size
Login.resizable(width=False, height=False)
# Creating title icon
Login.iconbitmap('img/loginlogo.ico')
# Top Frame
top_frame = Label(Login, text='Login',font = ('Cosmic', 25, 'bold'), bg='#bbfa0c',relief='groove',padx=500, pady=30)
top_frame.pack(side='top')
# Creating Frame
frame = LabelFrame(Login, padx=40, pady=30, bg='White')
frame.place(relx = 0.5, rely = 0.55, anchor = CENTER)
# Creating function for connecting to database and checking username
def Search(arg = None):
if username_entry.get() == '':
ms.showerror('Oops', 'Enter Username !!')
elif password_entry.get() == '':
ms.showerror('Oops', 'Enter Password !!')
else:
global username
username = username_entry.get()
global password
password = password_entry.get()
# Making connection
conn = sqlite3.connect('Database.db')
# Creating cursor
with conn:
cursor = conn.cursor()
# Searching for users
find_user = ('SELECT * FROM Users WHERE Username = ? AND Password = ?')
cursor.execute(find_user,(username, password))
results = cursor.fetchall()
print(results)
# if user then new window
if results:
Login.destroy()
system1 = tk.Tk()
# Creating size of window
system1.geometry('500x500')
# Background Colors
system1.configure(background='#7fb8f5')
# Locking the window size
system1.resizable(width=False, height=False)
# Creating Title
system1.title('Encrypt and Decrypt System')
# Top Frame
top_frame1 = Label(system1, text='WELCOME TO THE ImCrypt',font = ('Cosmic', 25, 'bold'), bg='#bbfa0c',relief='groove',padx=500, pady=30)
top_frame1.pack(side='top')
# Creating Frame
frame1 = LabelFrame(system1, padx=50, pady=30, bg='white', bd='5', relief='groove')
frame1.place(relx = 0.5, rely = 0.5, anchor = CENTER)
key1 = tk.Label(frame1, text = 'Key.', font=('Arial',12, 'bold'), bg='white', fg='green')
key1_entry = tk.Entry(frame1, font=('Arial',12,'normal'), bg='#FBB13C')
key1.pack()
key1_entry.pack()
# Label for seperating Buttons
label = Label(frame1, bg='white').pack()
def encrypt1():
conn1 = sqlite3.connect('Database.db')
with conn1:
cursor1 = conn1.cursor()
# Searching for users
find_key = ('SELECT * FROM Users')
cursor1.execute(find_key)
key_users = cursor1.fetchall()
print(username)
for key_user in key_users:
#print(key_user[2])
if (username == key_user[2]):
key = key_user[4]
#print(type(key_user[4]))
print(len(str(key)))
if key1_entry.get() == '':
ms.showerror('Oops', 'Enter key !!')
elif key1_entry.get() == str(key):
file1 = filedialog.askopenfile(mode='r')
if file1 is not None:
file_name = file1.name
enc = Encryptor(str(key))
enc.encrypt_file(file_name)
else:
ms.showerror('Oops', 'Key is invalid !!')
def decrypt1():
conn1 = sqlite3.connect('Database.db')
with conn1:
cursor1 = conn1.cursor()
# Searching for users
find_key = ('SELECT * FROM Users')
cursor1.execute(find_key)
key_users = cursor1.fetchall()
print(username)
for key_user in key_users:
#print(key_user[2])
if (username == key_user[2]):
key = key_user[4]
#print(type(key_user[4]))
print(len(str(key)))
if key1_entry.get() == '':
ms.showerror('Oops', 'Enter key !!')
elif key1_entry.get() == str(key):
file1 = filedialog.askopenfile(mode='r')
if file1 is not None:
file_name = file1.name
file1.close()
enc = Encryptor(str(key))
enc.decrypt_file(file_name)
else:
ms.showerror('Oops', 'Key is invalid !!')
# Creating Encrypt button and positioning it
Encrypt = tk.Button(frame1, text = "Encrypt", width="10", bd = '3', command = encrypt1, font = ('Times', 12, 'bold'), bg='#097eeb',relief='groove', justify = 'center', pady='5')
Encrypt.pack()
label = Label(frame1, bg='white').pack()
# Creating Decrypt button and positioning it
Decrypt = tk.Button(frame1, text = "Decrypt", width="10", bd = '3', command = decrypt1, font = ('Times', 12, 'bold'), bg='#4018f2',fg='white', relief='groove', justify = 'center', pady='5')
Decrypt.pack()
# Quit Button of main frame
def Quit():
response = ms.askokcancel('Exit!', 'Do you really want to exit ?')
if response == 1:
system.destroy()
else:
pass
Quit = tk.Button(system1, text = "Quit", width="10", command = system1.destroy, bd = '3', font = ('Times', 12, 'bold'), bg='black', fg='white',relief='groove', justify = 'center', pady='5')
Quit.place(anchor ='sw',rely=1,relx=0.775)
# Displyaing Widget to Screen
system1.mainloop()
else:
ms.showerror('Oops','User Not Found !! Check Username and Password Again !!')
# creating a label for username and password using Label
username = tk.Label(frame, text = 'Username',font=('Arial',12, 'bold'),bg='white', fg='green')
password = tk.Label(frame, text = 'Password', font = ('Arial',12,'bold'),bg='white', fg='green')
# creating a entry for username
username_entry = tk.Entry(frame, font=('calibre',10,'normal'), justify = 'center', bg='#FBB13C')
username_entry.bind('<Return>', Search)
password_entry=tk.Entry(frame, font = ('calibre',10,'normal'), show = '*', justify = 'center', bg='#FBB13C')
password_entry.bind('<Return>', Search)
# Button that will call the submit function
submit=tk.Button(frame,text = 'Login', command = Search, width="10",bd = '3', font = ('Times', 12, 'bold'), bg='#097eeb', fg='white',relief='groove', justify = 'center', pady='5')
# Placing the label and entry
username.pack()
username_entry.focus_set()
username_entry.pack()
# Label for seperating Buttons
label = Label(frame, bg='white').pack()
password.pack()
password_entry.pack()
# Label for seperating Buttons
label = Label(frame, bg='white').pack()
submit.pack()
# Quit Button
Quit = tk.Button(Login, text = "Quit", width="10", command = Login.destroy, bd = '3', font = ('Times', 12, 'bold'), bg='black', fg='white',relief='groove', justify = 'center', pady='5')
Quit.place(anchor ='sw',rely=1,relx=0.775)