-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
80 lines (58 loc) · 2.19 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
from utils.dbconfig import dbconfig
import config
import home as home
# function to check if password manager is already configured
def checkConfig():
# connect to database
db = dbconfig()
cursor = db.cursor()
# check if database password manager exists
query = "SHOW DATABASES LIKE 'passwordmanager'"
cursor.execute(query)
res = cursor.fetchone()
# if database passwordmanager exists
if res:
query = "USE passwordmanager"
cursor.execute(query)
# check if table secrets exists
query = "SHOW TABLES LIKE 'secrets'"
cursor.execute(query)
res_secrets = cursor.fetchone()
# if table secrets exists
if res_secrets:
# count number of rows in secrets table
query = "SELECT COUNT(*) FROM secrets"
cursor.execute(query)
count = cursor.fetchone()[0]
# if secrets table has only one row
if count == 1:
# check if table entries exists
query = "SHOW TABLES LIKE 'entries'"
cursor.execute(query)
res_entries = cursor.fetchone()
# return true if table entries exists
if res_entries:
return True
# if even one condition fails, delete the passwordmanager database. it will be reconfigured again correctly
query = "DROP DATABASE passwordmanager"
cursor.execute(query)
# return false if even any one of the above conditions fail
return False
# main function
def main():
# try configure password manager window
try:
root = config.config()
root.mainloop()
# if any exception, it might be that passwordmanager database already exists.
except:
# if password manager is configured properly, run authenticate password manager
if checkConfig():
root = home.auth()
root.mainloop()
# else if checkConfig() return false, then database passwordmanager is deleted. Reconfigure the password manager.
else:
root = config.config()
root.mainloop()
# run the main function
main()