hash the password.

This commit is contained in:
ASPP Student 2024-08-26 15:25:38 +03:00
parent 8e1d8309da
commit f1fc4c761d

18
auth.py
View file

@ -1,6 +1,7 @@
import json
import sys
from getpass import getpass
import hashlib
PWDB_PATH = 'pwdb.json'
@ -10,10 +11,10 @@ def get_credentials():
return (username, password)
def authenticate(username, password, pwdb):
return password == pwdb[username]
return pwhash(password) == pwdb[username]
def add_user(username, pwdb):
pwdb[username] = input(f'Enter password for {username}: ')
pwdb[username] = pwhash(input(f'Enter password for {username}: '))
return pwdb
def read_pwdb(PWDB_PATH):
@ -24,6 +25,19 @@ def read_pwdb(PWDB_PATH):
pwdb = {}
return pwdb
# def get_salt(username):
# ''' will return a unique variable'''
# salt =
# return salt
def pwhash(password):
hashed_pass = hashlib.sha256(password.encode('utf-8')).hexdigest()
return hashed_pass
def write_pwdb(pwdb, PWDB_PATH):
pwdb_file = open(PWDB_PATH, 'wt')
json.dump(pwdb, pwdb_file)