From c491ae0db3b9fe346553d2529660f458877096e0 Mon Sep 17 00:00:00 2001 From: caschick221 Date: Mon, 6 May 2024 16:06:57 -0400 Subject: [PATCH] added door sec level and user sec level check --- main.py | 79 ++++++++++++++++++++++++++++++++++++++++++++++++++++++--- 1 file changed, 75 insertions(+), 4 deletions(-) diff --git a/main.py b/main.py index 522cfb5..4ee7d44 100644 --- a/main.py +++ b/main.py @@ -58,6 +58,8 @@ doorID = config.get('Setup', 'doorID') gotAaguid = None GPIO.setmode(GPIO.BCM) +secLevel = 0 + greenLed = 14 redLed = 4 @@ -96,6 +98,8 @@ class CliInteraction(UserInteraction): print("User Verification required.") return True + + while True: GPIO.output(door, GPIO.LOW) @@ -231,6 +235,77 @@ while True: ) print("Credential authenticated!") + print("CLIENT DATA:", result.client_data) + print() + print("AUTH DATA:", result.authenticator_data) + # GPIO.output(14, GPIO.LOW) + + conn = None + try: + # Connect to the PostgreSQL server + conn = psycopg2.connect(dbname=dbname, user=user, password=password, host=host) + cur = conn.cursor() + select_query = ''' + SELECT sec_level + FROM users + WHERE "user_id" = %s; + ''' + # Execute the SQL query + cur.execute(select_query, (result[1])) + + # Fetch the results + result = None + result = cur.fetchone() + if result: + userSecLevel = result[0] + + else: + badCred() + raise Exception + + # Close communication with the database + cur.close() + except (Exception, psycopg2.DatabaseError) as error: + print(error) + raise Exception + finally: + if conn is not None: + conn.close() + + conn = None + try: + # Connect to the PostgreSQL server + conn = psycopg2.connect(dbname=dbname, user=user, password=password, host=host) + cur = conn.cursor() + select_query = ''' + SELECT sec_level + FROM door + WHERE "door_id" = %s; + ''' + # Execute the SQL query + cur.execute(select_query, (doorID)) + + # Fetch the results + result = None + result = cur.fetchone() + if result: + doorSecLevel = result[0] + + else: + badCred() + raise Exception + + # Close communication with the database + cur.close() + except (Exception, psycopg2.DatabaseError) as error: + print(error) + raise Exception + finally: + if conn is not None: + conn.close() + + if doorSecLevel < userSecLevel: + raise Exception GPIO.output(redLed, GPIO.LOW) for i in range(2): @@ -244,10 +319,6 @@ while True: time.sleep(5) GPIO.output(greenLed, GPIO.LOW) - print("CLIENT DATA:", result.client_data) - print() - print("AUTH DATA:", result.authenticator_data) - # GPIO.output(14, GPIO.LOW) except Exception as e: print("Authentication Failed!")