implement hashing method using hashlib

This commit is contained in:
ASPP Student 2024-08-26 15:29:41 +03:00
parent b42ef06d91
commit 8c16ff496e

12
auth.py
View file

@ -1,19 +1,27 @@
import json
import sys
from getpass import getpass
import hashlib
PWDB_PATH = 'pwdb.json'
def hashing(password):
pwd_string = bytes(str(password), 'utf-8')
hash_pwd = hashlib.sha256(pwd_string).hexdigest()
return hash_pwd
def get_credentials():
username = input('Enter your username: ')
password = getpass('Enter your password: ')
return (username, password)
hash_pwd = hashing(password)
return (username, hash_pwd)
def authenticate(username, password, pwdb):
return password == pwdb[username]
def add_user(username, pwdb):
pwdb[username] = input(f'Enter password for {username}: ')
password = input(f'Enter password for {username}: ')
pwdb[username] = hashing(password)
return pwdb
def read_pwdb(PWDB_PATH):