-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.py
executable file
·354 lines (303 loc) · 14.4 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
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
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
#Initialise Clover
import clover_init
clover_init.db_init()
#Import the rest of the modules
import sqlite3 as sql
import time
import sys ,os
import re
#PyQt Modules
from PyQt6.uic import loadUi
from PyQt6 import QtWidgets
from PyQt6.QtWidgets import QApplication, QDialog, QLabel, QProgressBar
from PyQt6.QtGui import QIcon, QPixmap, QFont, QFontDatabase
from PyQt6.QtCore import *
#Custom modules
import clover_cryptographer
import clover_stylesheets as styles
#Conncection to SQLite DB
activedb = sql.connect("CLOVER_DB.db")
cur = activedb.cursor()
time.sleep(2)
#Application Start
#Login Screen
class LoginScreen(QDialog): # Login Screen #AES DECRYPTION
def __init__(self):
#Load the UI
super(LoginScreen, self).__init__()
label = QLabel(self)
pixmap = QPixmap("rsrc/clover_login_bg_v1.png")
label.setPixmap(pixmap)
loadUi("clover_login.ui", self)
#Set the window title
app = QApplication(sys.argv)
self.setWindowTitle("Clover | Login")
#Set the window icon
app.setWindowIcon(QIcon("rsrc/clover_icon.png"))
#Assign functions to buttons
self.loginbutton.clicked.connect(self.loginfunction)
self.signupbutton.clicked.connect(self.gotocreate)
#UI Styling
self.loginbutton.setStyleSheet(styles.button_style)
self.signupbutton.setStyleSheet(styles.button_style)
self.usrnmfield.setStyleSheet(styles.form_style)
self.pwdfield.setStyleSheet(styles.form_style)
#Login Function
def loginfunction(self):
global user #global variable for the user
user = self.usrnmfield.text().lower() #Get the username
password = self.pwdfield.text() #Get the password
#Check if the username exists
cur.execute(f"SELECT COUNT(CLOVER_USRNM) FROM CLOVER_MASTERDB WHERE CLOVER_USRNM = '{user}'")
row_count = cur.fetchall()
def login():
if len(user) == 0 or len(password) == 0: #Check if the fields are empty
self.alertbox.setText("Please Input all Fields!")
timer.singleShot(2000, self.clear_alertbox)
elif row_count[0][0] == 0: #Check if the username exists
self.alertbox.setText("Login Credentials Not Found.\nPlease Create an Account First!")
timer.singleShot(2000, self.clear_alertbox)
else:
#Check if the password is correct
cur.execute(f"SELECT nKEY FROM CLOVER_MASTERDB WHERE CLOVER_USRNM = '{user}' or CLOVER_EMAIL = '{user}'")
special_key = cur.fetchone()
hashed_pwd = clover_cryptographer.hash(password, special_key[0])
cur.execute(f"SELECT CLOVER_PWD FROM CLOVER_MASTERDB WHERE CLOVER_USRNM = '{user}' or CLOVER_EMAIL = '{user}'")
result = cur.fetchall()
if len(result) == 0:
self.alertbox.setText("Invalid Username or Email!")
timer.singleShot(2000, self.clear_alertbox)
elif hashed_pwd == result[0][0]: #If the password is correct
self.alertbox.setText("Authenticated!\nPress Login again to continue.")
timer.singleShot(2000, self.clear_alertbox)
self.loginbutton.clicked.connect(self.gotodashboard)
else: #If the password is incorrect
self.alertbox.setText("Invalid Password!")
timer.singleShot(2000, self.clear_alertbox)
login() #Call the login function
def gotocreate(self): #signup page link
signup = SignUpScreen()
widget.addWidget(signup)
widget.setCurrentIndex(widget.currentIndex() + 1)
def gotodashboard(self): #dashboard page link
dashboard = DashboardScreen()
widget.addWidget(dashboard)
widget.setCurrentIndex(widget.currentIndex() + 1)
def clear_alertbox(self):
self.alertbox.setText("")
#Signup Screen
class SignUpScreen(QDialog): # Sign Up Screen
def __init__(self):
super(SignUpScreen, self).__init__()
label = QLabel(self)
pixmap = QPixmap("rsrc/clover_login_bg_v2.png")
label.setPixmap(pixmap)
loadUi("clover_signup.ui",self)
#Assiging Functions to buttons
self.returnbtn.clicked.connect(self.gotologin)
self.signupbutton.clicked.connect(self.SignUpFunction)
#UI Styling
self.returnbtn.setIcon(QIcon("rsrc/return_icon.png"))
self.signupbutton.setStyleSheet(styles.button_style)
self.usrnmfield.setStyleSheet(styles.form_style)
self.pwdfield.setStyleSheet(styles.form_style)
self.emailfield.setStyleSheet(styles.form_style)
self.cnfpwdfield.setStyleSheet(styles.form_style)
def SignUpFunction(self): # This is the sign up function
user = self.usrnmfield.text().lower()
email = self.emailfield.text().lower()
password = self.pwdfield.text()
password_b = self.cnfpwdfield.text()
cur.execute(f"SELECT count(CLOVER_USRNM) FROM CLOVER_MASTERDB WHERE CLOVER_USRNM = '{user}'")
checkUser = cur.fetchall()
cur.execute(f"SELECT count(CLOVER_EMAIL) FROM CLOVER_MASTERDB WHERE CLOVER_EMAIL = '{email}'")
checkEmail = cur.fetchall()
if len(user)==0 or len(password)==0 or len(email)==0 or len(password_b)==0:
self.alertbox.setText("Please input all fields.")
timer.singleShot(2000, self.clear_alertbox)
elif (re.fullmatch(regex, email)) == None:
self.alertbox.setText("Please input a valid email.")
timer.singleShot(2000, self.clear_alertbox)
elif password != password_b:
self.alertbox.setText("Passwords do not match, Try Again!")
timer.singleShot(2000, self.clear_alertbox)
elif len(password) < 8:
self.alertbox.setText("Password must be atleast 8 characters long!")
timer.singleShot(2000, self.clear_alertbox)
elif checkUser == [(1,)]:
self.alertbox.setText("Username already exists! Try another one.")
timer.singleShot(2000, self.clear_alertbox)
elif checkEmail == [(1,)]:
self.alertbox.setText("Email already exists! Try another one.")
timer.singleShot(2000, self.clear_alertbox)
else:
user_db = user + "_clover_appdb"
salt = clover_cryptographer.caesar_encrypt(user, 8)
hashed_pwd = clover_cryptographer.hash(password, salt)
self.alertbox.setText(f"{user_db}, {email}, {password}, {password_b}, {hashed_pwd}") #testing
cur.execute(f"CREATE TABLE if not exists {user_db}(email varchar(50), appname varchar(20) NOT NULL, app_password varchar(100) NOT NULL);")
cur.execute(f"INSERT INTO CLOVER_MASTERDB(CLOVER_USRNM, CLOVER_EMAIL, CLOVER_PWD, nKEY) VALUES('{user}','{email}', '{hashed_pwd}', '{salt}')")
activedb.commit()
self.alertbox.setText("Account Created Successfully!\nRedirecting to Login Screen...")
timer.singleShot(1000, self.gotologin)
def gotologin(self):
login = LoginScreen()
widget.addWidget(login)
widget.setCurrentIndex(widget.currentIndex() + 1)
def clear_alertbox(self):
self.alertbox.setText("")
class DashboardScreen(QDialog): # Dashboard Screen
def __init__(self):
super(DashboardScreen, self).__init__()
label = QLabel(self)
pixmap = QPixmap("rsrc/dashboard_art.png")
label.setPixmap(pixmap)
loadUi("clover_dashboard.ui",self)
#Load Button Functions
self.logoutbtn.clicked.connect(self.logoutfunction) #LogOut Function
self.addbtn.clicked.connect(self.add_app) #Add App Function
self.removebtn.clicked.connect(self.remove_app) #Remove App Function
self.applist.clicked.connect(self.display_details) #App Display Function
self.generatepwd.clicked.connect(self.generate_password) #Generate Password Function
self.copypwd.clicked.connect(self.CtCpwd) #Copy to Clipboard Function
# Load Button Icons
self.logoutbtn.setIcon(QIcon("rsrc/logout_icon.png"))
self.addbtn.setIcon(QIcon("rsrc/add_icon.png"))
self.removebtn.setIcon(QIcon("rsrc/remove_icon.png"))
#UI Styling
self.cbody.setStyleSheet("background-color: #0c0d0c;")
self.usrnm.setStyleSheet("color: #FFFFFF; font-size: 30px; font-weight: 200;")
self.applist.setStyleSheet(styles.list_style)
self.appfield.setStyleSheet(styles.form_style2)
self.emailfield.setStyleSheet(styles.form_style2)
self.generatepwd.setStyleSheet(styles.button_style2)
self.copypwd.setStyleSheet(styles.button_style2)
self.addbtn.setStyleSheet(styles.button_style2)
self.appname.setStyleSheet(styles.block_style)
self.emailid.setStyleSheet(styles.block_style)
self.logoutbtn.setStyleSheet(styles.logout_button)
global active_user
active_user = user
self.usrnm.setText(active_user)
#Load App List
self.applist.clear()
cur.execute(f"SELECT appname FROM {active_user}_clover_appdb")
app_list = cur.fetchall()
for app in app_list:
self.applist.addItem(app[0])
#Add items to list
def add_app(self):
if len(self.appfield.text()) == 0:
self.alertbox.setText("Please input an app name!")
self.alertbox.setStyleSheet(styles.alert)
timer.singleShot(2000, self.clear_alertbox)
elif len(self.emailfield.text()) == 0:
self.alertbox.setText("Please input an email!")
self.alertbox.setStyleSheet(styles.alert)
timer.singleShot(2000, self.clear_alertbox)
elif (re.fullmatch(regex, self.emailfield.text())) == None:
self.alertbox.setText("Please input a valid email.")
self.alertbox.setStyleSheet(styles.alert)
timer.singleShot(2000, self.clear_alertbox)
else:
app_name = self.appfield.text()
self.applist.addItem(app_name)
app_email = self.emailfield.text()
app_password = clover_cryptographer.pwd_generator()
cur.execute(f"INSERT INTO {active_user}_clover_appdb(appname, email, app_password) VALUES('{app_name}', '{app_email}', '{app_password}')")
activedb.commit()
self.appfield.setText("")
self.emailfield.setText("")
self.alertbox.setText("App Added!")
self.alertbox.setStyleSheet(styles.success)
timer.singleShot(2000, self.clear_alertbox)
def generate_password(self):
if self.applist.currentItem() == None:
self.alertbox.setText("Please select an app!")
self.alertbox.setStyleSheet(styles.alert)
timer.singleShot(2000, self.clear_alertbox)
else:
app_name = self.applist.currentItem().text()
#Generate Password
app_password = clover_cryptographer.pwd_generator()
#Add to DB
cur.execute(f"UPDATE {active_user}_clover_appdb SET app_password = '{app_password}' WHERE appname = '{app_name}'")
activedb.commit()
#Copy to Clipboard
cb = QApplication.clipboard()
cb.clear()
cb.setText(app_password)
self.alertbox.setText("Password Generated and Copied!")
self.alertbox.setStyleSheet(styles.success)
timer.singleShot(2000, self.clear_alertbox)
def CtCpwd(self):
while self.applist.currentItem() == None:
self.alertbox.setText("Please select an app!")
self.alertbox.setStyleSheet(styles.alert)
timer.singleShot(2000, self.clear_alertbox)
break
else:
#Copy to Clipboard
app_name = self.applist.currentItem().text()
cb = QApplication.clipboard()
cb.clear()
cur.execute(f"SELECT app_password FROM {active_user}_clover_appdb WHERE appname = '{app_name}'")
app_password = cur.fetchone()[0]
cb.setText(app_password)
self.alertbox.setText("Password Copied to Clipboard!")
timer.singleShot(2000, self.clear_alertbox)
self.alertbox.setStyleSheet(styles.success)
#Remove items from list
def remove_app(self):
while self.applist.currentItem() == None:
self.alertbox.setText("Please select an app!")
self.alertbox.setStyleSheet(styles.alert)
timer.singleShot(2000, self.clear_alertbox)
break
else:
app_name = self.applist.currentRow()
app_item = self.applist.currentItem().text()
self.applist.takeItem(app_name)
self.appname.setText("")
cur.execute(f"DELETE FROM {active_user}_clover_appdb WHERE appname = '{app_item}'")
activedb.commit()
self.alertbox.setText("App Removed!")
self.alertbox.setStyleSheet(styles.success)
#Display App Data
def display_details(self):
while self.applist.currentItem() != None:
app_name = self.applist.currentItem().text()
cur.execute(f"SELECT email FROM {active_user}_clover_appdb WHERE appname = '{app_name}'")
email = cur.fetchone()[0]
self.appname.setText(app_name)
self.emailid.setText(email)
break
#Clear Alert Box
def clear_alertbox(self):
self.alertbox.setText("")
self.alertbox.setStyleSheet("background-color: #00000000; color: #000000;")
#LogOut Function
def logoutfunction(self): #[WIP]
login = LoginScreen()
widget.addWidget(login)
widget.setCurrentIndex(widget.currentIndex() + 1)
app = QApplication(sys.argv)
mainwindow = LoginScreen()
widget = QtWidgets.QStackedWidget()
widget = QtWidgets.QStackedWidget()
widget.addWidget(mainwindow)
widget.setFixedWidth(930)
widget.setFixedHeight(500)
widget.show()
#Font
ROOT_DIR = os.path.realpath(os.path.join(os.path.dirname(__file__), '.'))
ffl = os.path.join(ROOT_DIR, 'rsrc', 'Gilroy.ttf')
id = QFontDatabase.addApplicationFont(ffl)
families = QFontDatabase.applicationFontFamilies(id)
current_font = families[0]
app.setFont(QFont(current_font, 10))
#Misceallaneous
regex = r'\b[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Z|a-z]{2,}\b'
timer = QTimer()
sys.exit(app.exec())
#abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890!@#$%^&*()_+~`|}{[]\:;?><,./-=