hash password #8

Open
alessiase wants to merge 1 commit from alessiase/2024-heraklion-git:hashpwd into main

View file

@ -9,11 +9,16 @@ def get_credentials():
password = getpass('Enter your password: ') password = getpass('Enter your password: ')
return (username, password) return (username, password)
def get_hash(password):
_hash = sum([ord(letter) for letter in password])
return _hash
def authenticate(username, password, pwdb): def authenticate(username, password, pwdb):
return password == pwdb[username] return password == pwdb[username]
def add_user(username, pwdb): 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 return pwdb
def read_pwdb(PWDB_PATH): def read_pwdb(PWDB_PATH):
@ -41,7 +46,7 @@ if __name__ == "__main__":
if username not in pwdb: if username not in pwdb:
print('Wrong username!') print('Wrong username!')
else: else:
if authenticate(username, password, pwdb): if authenticate(username, get_hash(password), pwdb):
print('Successfully authenticated!') print('Successfully authenticated!')
else: else:
print('Wrong password!') print('Wrong password!')