add salting to hash function

This commit is contained in:
ASPP Student 2024-08-26 15:57:30 +03:00
parent 0113bf68b9
commit ca678f9721

View file

@ -7,14 +7,14 @@ PWDB_PATH = 'pwdb.json'
def get_credentials():
username = input('Enter your username: ')
hashed_password = pwhash(getpass('Enter your password: '))
hashed_password = pwhash(username, getpass('Enter your password: '))
return (username, hashed_password)
def authenticate(username, hashed_password, pwdb):
return hashed_password == pwdb[username]
def add_user(username, pwdb):
pwdb[username] = pwhash(getpass(f'Enter password for {username}: '))
pwdb[username] = pwhash(username, getpass(f'Enter password for {username}: '))
return pwdb
def read_pwdb(PWDB_PATH):
@ -30,9 +30,10 @@ def write_pwdb(pwdb, PWDB_PATH):
json.dump(pwdb, pwdb_file)
def pwhash(pwd):
def pwhash(username , pwd):
encoded_pwd = pwd.encode("utf-8")
m = sha256()
encoded_usr = username.encode("utf-8")
m = sha256(encoded_usr) # salting with username
m.update(encoded_pwd)
return m.hexdigest()