From 0cb4e352992953b6dcfd2dd6b0edebca27f2c18a Mon Sep 17 00:00:00 2001 From: ASPP Student Date: Mon, 26 Aug 2024 15:15:14 +0300 Subject: [PATCH] Implement hashlib password hashing; print hashpass --- auth.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/auth.py b/auth.py index 1559a08..8ca3b30 100644 --- a/auth.py +++ b/auth.py @@ -1,6 +1,7 @@ import json import sys from getpass import getpass +import hashlib PWDB_PATH = 'pwdb.json' @@ -16,6 +17,11 @@ def add_user(username, pwdb): pwdb[username] = input(f'Enter password for {username}: ') return pwdb +def pwhash(password): + byte_pass = bytes(password, 'UTF-8') + hashed_password = hashlib.sha256() + hashed_password.update(byte_pass) + return print(hashed_password.digest()) def read_pwdb(PWDB_PATH): try: pwdb_file = open(PWDB_PATH, 'rt') @@ -45,4 +51,5 @@ if __name__ == "__main__": print('Successfully authenticated!') else: print('Wrong password!') + pwhash(password)