From 7d3a0d6bd97889c11bb2ec741f0f308613602c6d Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Mon, 26 Aug 2024 15:26:04 +0300 Subject: [PATCH 1/2] hash password upon creation --- auth.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/auth.py b/auth.py index 1559a08..2349347 100644 --- a/auth.py +++ b/auth.py @@ -6,6 +6,7 @@ PWDB_PATH = 'pwdb.json' def get_credentials(): username = input('Enter your username: ') + password = hash_psw(getpass('Enter your password: ')) password = getpass('Enter your password: ') return (username, password) @@ -13,6 +14,7 @@ def authenticate(username, password, pwdb): return password == pwdb[username] def add_user(username, pwdb): + pwdb[username] = hash_psw(input(f'Enter password for {username}: ')) pwdb[username] = input(f'Enter password for {username}: ') return pwdb -- 2.39.5 From 290926b345793c41f74d6a2142a1730305eeab16 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Mon, 26 Aug 2024 15:27:13 +0300 Subject: [PATCH 2/2] add hash function --- auth.py | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/auth.py b/auth.py index 2349347..1fbeb21 100644 --- a/auth.py +++ b/auth.py @@ -1,13 +1,13 @@ import json import sys from getpass import getpass +import hashlib PWDB_PATH = 'pwdb.json' def get_credentials(): username = input('Enter your username: ') password = hash_psw(getpass('Enter your password: ')) - password = getpass('Enter your password: ') return (username, password) def authenticate(username, password, pwdb): @@ -15,9 +15,13 @@ def authenticate(username, password, pwdb): def add_user(username, pwdb): pwdb[username] = hash_psw(input(f'Enter password for {username}: ')) - pwdb[username] = input(f'Enter password for {username}: ') return pwdb +def hash_psw(password): + hashed_pw = hashlib.sha256(bytes(password, 'utf-8')).hexdigest() + return hashed_pw + + def read_pwdb(PWDB_PATH): try: pwdb_file = open(PWDB_PATH, 'rt') -- 2.39.5