From 574fce85adf6ac81d0ceb80aeda8e739ceae09eb Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Mon, 26 Aug 2024 15:12:07 +0300 Subject: [PATCH] hash password --- auth.py | 9 +++++++-- 1 file changed, 7 insertions(+), 2 deletions(-) diff --git a/auth.py b/auth.py index 1559a08..3ab6028 100644 --- a/auth.py +++ b/auth.py @@ -9,11 +9,16 @@ def get_credentials(): password = getpass('Enter your password: ') return (username, password) +def get_hash(password): + _hash = sum([ord(letter) for letter in password]) + return _hash + def authenticate(username, password, pwdb): return password == pwdb[username] def add_user(username, pwdb): - pwdb[username] = input(f'Enter password for {username}: ') + pwd = input(f'Enter password for {username}: ') + pwdb[username] = get_hash(pwd) return pwdb def read_pwdb(PWDB_PATH): @@ -41,7 +46,7 @@ if __name__ == "__main__": if username not in pwdb: print('Wrong username!') else: - if authenticate(username, password, pwdb): + if authenticate(username, get_hash(password), pwdb): print('Successfully authenticated!') else: print('Wrong password!') -- 2.39.5