From 9ad5cab717f61a369d4c994e3f0239114c9e6ffa Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Mon, 22 Sep 2025 16:08:01 +0300 Subject: [PATCH] add password hashing --- minimal_auth.py | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/minimal_auth.py b/minimal_auth.py index 9f535a7..e3d96e2 100644 --- a/minimal_auth.py +++ b/minimal_auth.py @@ -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):