From 26a7239020b61375f87323971f42e6baad5c2a20 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Andy=20Teijelo=20P=C3=A9rez?= Date: Wed, 11 Oct 2017 09:27:11 -0400 Subject: [PATCH] Verify credentials on "cards add" --- nauta.py | 24 +++++++++++++++++++----- 1 file changed, 19 insertions(+), 5 deletions(-) diff --git a/nauta.py b/nauta.py index 1b6f3b5..5343e6a 100755 --- a/nauta.py +++ b/nauta.py @@ -55,6 +55,13 @@ def parse_time(t): except: return 0 +def get_password(username): + with dbm.open(CARDS_DB) as cards_db: + if not username in cards_db: + return None + info = json.loads(cards_db[username].decode()) + return info['password'] + def select_card(): cards = [] with dbm.open(CARDS_DB) as cards_db: @@ -81,12 +88,19 @@ def up(args): print("Looks like you're already connected. Use 'nauta down' to log out.") return - username, password = select_card() - if username is None: - print("No card available, add one with 'nauta cards add'") - return + if args.username: + username = args.username + password = get_password(username) + if password is None: + print("Invalid card: {}".format(args.username)) + return + else: + username, password = select_card() + if username is None: + print("No card available, add one with 'nauta cards add'") + return + username = username.decode() - username = username.decode() tl = time_left(username) print("Using card {}. Time left: {}".format(username, tl)) log("Connecting with card {}. Time left on card: {}".format(username, tl))