add password hashing

This commit is contained in:
ASPP Student 2025-09-22 16:08:01 +03:00
parent 33469b8840
commit 9ad5cab717

View file

@ -1,6 +1,7 @@
import getpass # hides types characters, very useful
import json
import sys
import hashlib # python standard lib for hashing
def get_credentials():
username = input('Enter your username: ')
@ -11,7 +12,9 @@ def authenticate(username, password, pwdb):
return password == pwdb[username]
def add_user(username, pwdb):
pwdb[username] = getpass.getpass(f'Enter password for {username}: ')
password = getpass.getpass(f'Enter password for {username}: ')
# hash the password before saving to the database
pwdb[username] = hashlib.sha256(f'{password}'.encode()).hexdigest()
return pwdb
def read_pwdb(pwdb_path):