From e149ba772401cf1ebbeb53da5b52e477a466a344 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Mon, 22 Sep 2025 16:00:48 +0300 Subject: [PATCH] Use sha256 to encode passwords instead of plain text --- minimal_auth.py | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/minimal_auth.py b/minimal_auth.py index 9f535a7..5c317a6 100644 --- a/minimal_auth.py +++ b/minimal_auth.py @@ -1,17 +1,19 @@ import getpass # hides types characters, very useful import json import sys +import hashlib def get_credentials(): username = input('Enter your username: ') - password = getpass.getpass('Enter your password: ') + password = str(hashlib.sha256(getpass.getpass('Enter your password: ').encode()).hexdigest()) return (username, password) 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}: ') + pwdb[username] = str(hashlib.sha256(password.encode()).hexdigest()) return pwdb def read_pwdb(pwdb_path): -- 2.39.5