From 1e9b41120cefebcd3b3be4591efa763e258a38d5 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Mon, 22 Sep 2025 16:03:20 +0300 Subject: [PATCH] fixed visible passwords --- minimal_auth.py | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/minimal_auth.py b/minimal_auth.py index 9f535a7..cc1a791 100644 --- a/minimal_auth.py +++ b/minimal_auth.py @@ -1,17 +1,24 @@ import getpass # hides types characters, very useful import json import sys +import hashlib + +def create_hash(password): + m = hashlib.sha256(password.encode('utf-8')) + pw_hex = m.hexdigest() + return pw_hex def get_credentials(): username = input('Enter your username: ') password = getpass.getpass('Enter your password: ') - return (username, password) + pw_hashed = create_hash(password) + return (username, pw_hashed) def authenticate(username, password, pwdb): return password == pwdb[username] def add_user(username, pwdb): - pwdb[username] = getpass.getpass(f'Enter password for {username}: ') + pwdb[username] = create_hash(getpass.getpass(f'Enter password for {username}: ')) return pwdb def read_pwdb(pwdb_path): -- 2.39.5