From 4dc47e547ab3feebdd9152fad9d4e4e3f6d65fb7 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Mon, 26 Aug 2024 14:57:38 +0300 Subject: [PATCH 1/3] define hash function --- auth.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/auth.py b/auth.py index 1559a08..040ada8 100644 --- a/auth.py +++ b/auth.py @@ -28,6 +28,11 @@ def write_pwdb(pwdb, PWDB_PATH): pwdb_file = open(PWDB_PATH, 'wt') json.dump(pwdb, pwdb_file) +def hash_password(password): + hash = 0 + for c in password.split(): + hash += ord(c) + return hash if __name__ == "__main__": PWDB_PATH = 'pwdb.json' -- 2.39.5 From 3dd3e3e3104e04f086cefe8710a9fafcb79d27aa Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Mon, 26 Aug 2024 15:04:40 +0300 Subject: [PATCH 2/3] use hashed password function for authentification --- auth.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/auth.py b/auth.py index 040ada8..49d8d97 100644 --- a/auth.py +++ b/auth.py @@ -10,10 +10,10 @@ def get_credentials(): return (username, password) def authenticate(username, password, pwdb): - return password == pwdb[username] + return hash_password(password) == pwdb[username] def add_user(username, pwdb): - pwdb[username] = input(f'Enter password for {username}: ') + pwdb[username] = hash_password(input(f'Enter password for {username}: ')) return pwdb def read_pwdb(PWDB_PATH): -- 2.39.5 From b572fd0e7ee3133b5c68c68ae629ccaaffef9730 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Mon, 26 Aug 2024 15:30:59 +0300 Subject: [PATCH 3/3] salt the hash --- auth.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/auth.py b/auth.py index 49d8d97..dd6be6e 100644 --- a/auth.py +++ b/auth.py @@ -29,10 +29,14 @@ def write_pwdb(pwdb, PWDB_PATH): json.dump(pwdb, pwdb_file) def hash_password(password): - hash = 0 + hash_1 = 0 for c in password.split(): - hash += ord(c) - return hash + hash_1 += ord(c) + hash_2 = int(log(hash_1) * 100000) + hash_3 = 1 + for d in list(str(hash_2)): + hash_3 *= ord(d) + return hash_3 if __name__ == "__main__": PWDB_PATH = 'pwdb.json' -- 2.39.5