Implement simple password hashing #9

Open
antoninfo wants to merge 2 commits from antoninfo/2024-heraklion-git:hashing into main

View file

@ -10,12 +10,17 @@ def get_credentials():
return (username, password) return (username, password)
def authenticate(username, password, pwdb): def authenticate(username, password, pwdb):
return password == pwdb[username] return pwhash(password) == pwdb[username]
def add_user(username, pwdb): def add_user(username, pwdb):
pwdb[username] = input(f'Enter password for {username}: ') password = getpass(f'Enter password for {username}: ')
pwdb[username] = pwhash(password)
return pwdb 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): def read_pwdb(PWDB_PATH):
try: try:
pwdb_file = open(PWDB_PATH, 'rt') pwdb_file = open(PWDB_PATH, 'rt')