Implement Hashing for passwords in pwdb

This commit is contained in:
ASPP Student 2024-08-26 15:32:17 +03:00
parent 0cb4e35299
commit 267758002f

View file

@ -11,17 +11,18 @@ def get_credentials():
return (username, password)
def authenticate(username, password, pwdb):
return password == pwdb[username]
return pwash(password) == pwdb[username]
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
def pwhash(password):
byte_pass = bytes(password, 'UTF-8')
hashed_password = hashlib.sha256()
hashed_password.update(byte_pass)
return print(hashed_password.digest())
return str(hashed_password.digest())
def read_pwdb(PWDB_PATH):
try:
pwdb_file = open(PWDB_PATH, 'rt')