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: ')
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!')