phash #17

Open
ariannabi wants to merge 2 commits from ariannabi/2024-heraklion-git:phash into main
Showing only changes of commit 267758002f - Show all commits

View file

@ -11,17 +11,18 @@ def get_credentials():
return (username, password) return (username, password)
def authenticate(username, password, pwdb): def authenticate(username, password, pwdb):
return password == pwdb[username] return pwash(password) == pwdb[username]
def add_user(username, pwdb): def add_user(username, pwdb):
pwdb[username] = input(f'Enter password for {username}: ') password = input(f'Enter password for {username}: ')
pwdb[username] = pwhash(password)
return pwdb return pwdb
def pwhash(password): def pwhash(password):
byte_pass = bytes(password, 'UTF-8') byte_pass = bytes(password, 'UTF-8')
hashed_password = hashlib.sha256() hashed_password = hashlib.sha256()
hashed_password.update(byte_pass) hashed_password.update(byte_pass)
return print(hashed_password.digest()) return str(hashed_password.digest())
def read_pwdb(PWDB_PATH): def read_pwdb(PWDB_PATH):
try: try:
pwdb_file = open(PWDB_PATH, 'rt') pwdb_file = open(PWDB_PATH, 'rt')