diff --git a/minimal_auth.py b/minimal_auth.py index 9f535a7..1d3c834 100644 --- a/minimal_auth.py +++ b/minimal_auth.py @@ -1,6 +1,7 @@ import getpass # hides types characters, very useful import json import sys +from hashlib import sha256 # This library is used to create hashes out of the password def get_credentials(): username = input('Enter your username: ') @@ -8,10 +9,12 @@ def get_credentials(): return (username, password) def authenticate(username, password, pwdb): - return password == pwdb[username] + password_hash = sha256(password.encode("utf-8")).hexdigest() + return password_hash == pwdb[username] def add_user(username, pwdb): - pwdb[username] = getpass.getpass(f'Enter password for {username}: ') + pwd = getpass.getpass(f'Enter password for {username}: ') + pwdb[username] = sha256(pwd.encode("utf-8")).hexdigest() return pwdb def read_pwdb(pwdb_path):