From 7ed1ba6cf46ad4fd19fa2086787750803b37911c Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Mon, 26 Aug 2024 15:02:27 +0300 Subject: [PATCH 1/2] Implement hashing --- auth.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/auth.py b/auth.py index 1559a08..84da6da 100644 --- a/auth.py +++ b/auth.py @@ -10,12 +10,17 @@ def get_credentials(): return (username, password) def authenticate(username, password, pwdb): - return password == pwdb[username] + return pwhash(password) == pwdb[username] def add_user(username, pwdb): - pwdb[username] = input(f'Enter password for {username}: ') + password = input(f'Enter password for {username}: ') + pwdb[username] = pwhash(password) return pwdb +def pwhash(password): + ord_password_num = [int(ord(character)) for character in password] + return sum(ord_password_num) + def read_pwdb(PWDB_PATH): try: pwdb_file = open(PWDB_PATH, 'rt') -- 2.39.5 From 29fb7baa21b69bfb1b11b1b642eec7d2ab651e1d Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Mon, 26 Aug 2024 15:11:40 +0300 Subject: [PATCH 2/2] Fix visible password --- auth.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/auth.py b/auth.py index 84da6da..8e80d62 100644 --- a/auth.py +++ b/auth.py @@ -13,7 +13,7 @@ def authenticate(username, password, pwdb): return pwhash(password) == pwdb[username] def add_user(username, pwdb): - password = input(f'Enter password for {username}: ') + password = getpass(f'Enter password for {username}: ') pwdb[username] = pwhash(password) return pwdb -- 2.39.5