-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
66 lines (56 loc) · 1.95 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
import passwordgenerator
import sqlquery
import db_connect
import psycopg2
import argparse
import master_password
import getpass
import sys
import hashlib
import logging
logger = logging.getLogger(__name__)
logging.basicConfig(level=logging.INFO)
def authenticate_user():
master_password_input = getpass.getpass("Master Password: ").encode()
second_FA_location = "Dee Boo Dah".encode()
master_password_hash = hashlib.sha256(master_password_input + second_FA_location).hexdigest()
if master_password.query_master_pwd(master_password_input, second_FA_location):
connection = db_connect.connection_db()
logger.info("Authentication successful")
return connection
else:
logger.error("Authentication failed")
sys.exit(1)
def add_entry(cursor, master_password_hash, args):
# ... (similar to original code, but with error handling and potential improvements)
# Example:
try:
# ... database operations
except psycopg2.Error as e:
logger.error(f"Error adding entry: {e}")
def query_entry(cursor, master_password_hash, args):
# ... (similar to original code, but with error handling and potential improvements)
# Example:
try:
# ... database operations
except psycopg2.Error as e:
logger.error(f"Error querying entry: {e}")
# ... other functions for different operations
def main():
parser = argparse.ArgumentParser(...)
args = parser.parse_args()
connection = authenticate_user()
cursor = connection.cursor()
try:
if args.add:
add_entry(cursor, master_password_hash, args)
elif args.query:
query_entry(cursor, master_password_hash, args)
# ... other operations
except Exception as e:
logger.error(f"Unexpected error: {e}")
finally:
cursor.close()
connection.close()
if __name__ == "__main__":
main()