-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
122 lines (99 loc) · 3.51 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
from database import PasswordDB
from crypto import encrypt, decrypt
from password_generator import generateRandomPassword
from authenticate import authenticatePassword, authenticateFace
import pyperclip # For using clipboard
from decouple import config # For storing environment variables
from texttable import Texttable # For clearing beautiful tables
# Extracting the environment variables.
SECRET_KEY = config('SECURITY_KEY')
AUTHENTICATION_TYPE = config('AUTHENTICATION_TYPE')
# Initializing database.
db = PasswordDB()
def accessPassword():
print('Enter the name of the website.')
website = input(">>>")
print('Enter the email.')
email = input(">>>")
password = db.getPassword(website, email)
if(len(password) == 0):
print("Password does not exist.")
else:
password = decrypt(SECRET_KEY, password[0][0])
pyperclip.copy(password)
print("Your password is copied to clipboard!")
def savePassword():
print('Enter the name of the website.')
website = input(">>>")
print('Enter the user name.')
user_name = input(">>>")
print('Enter the email.')
email = input(">>>")
print("For creating a system generated strong random password, enter 'y' or 'n'")
is_random_pass = input(">>>")
if is_random_pass == 'y':
password = generateRandomPassword()
else:
print("Enter your own password.")
password = input(">>>")
password = encrypt(SECRET_KEY, password)
db.savePassword(website, user_name, email, password)
def deletePassword():
print('Enter the name of the website.')
website = input(">>>")
print('Enter the email.')
email = input(">>>")
db.deletePassword(website, email)
# Displays all the saved passwords.
def showAllPasswords():
records = db.showAllPasswords()
table = Texttable()
table.add_rows([["Website", "User Name", "Email"]] + records)
print(table.draw())
# Display the available commands table.
def showCommands():
table = Texttable()
table.add_rows([["Command", "Function"],
["cmd", "Display this box of available commands."],
["get", "Access a saved password."],
["save", "Save a new password."],
["del", "Delete an existing password."],
["all", "Show all saved passwords."],
["exit()", "Exit the program."]])
print(table.draw())
def cli():
print("Welcome to the command-line interface of Pass-Mgr.")
print("I am a locker that will safely store all your passwords.\n")
auth = False
if AUTHENTICATION_TYPE == '1':
print("To access saved passwords or save new password, enter the root password.")
auth = authenticatePassword()
if AUTHENTICATION_TYPE == '2':
print('Authenticating Face.')
auth = authenticateFace()
if(auth):
print("\n\n\t\tAccess granted!")
else:
print("Invalid authentication.")
exit()
showCommands()
command = "dummy"
while command != "exit()":
command = input(">>>").lower()
if command == "get":
accessPassword()
elif command == "save":
savePassword()
elif command == "del":
deletePassword()
elif command == "all":
showAllPasswords()
elif command == "cmd":
showCommands()
elif command == "exit()":
pass
else:
print("Enter a valid command")
exit()
if __name__ == "__main__":
cli()