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):