From 290926b345793c41f74d6a2142a1730305eeab16 Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Mon, 26 Aug 2024 15:27:13 +0300 Subject: [PATCH] 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')