add password hashing #8
1 changed files with 9 additions and 2 deletions
|
@ -8,13 +8,20 @@ def get_credentials():
|
|||
password = getpass.getpass('Enter your password: ')
|
||||
return (username, password)
|
||||
|
||||
# add a function that hashes the password
|
||||
def hash_password(password):
|
||||
return hashlib.sha256(f'{password}'.encode()).hexdigest()
|
||||
|
||||
def authenticate(username, password, pwdb):
|
||||
return password == pwdb[username]
|
||||
correct_password = pwdb[username]
|
||||
# add this line to hash the entered password to then compared with the stored password
|
||||
attempted_password = hash_password(password)
|
||||
return correct_password == attempted_password
|
||||
|
||||
def add_user(username, pwdb):
|
||||
password = getpass.getpass(f'Enter password for {username}: ')
|
||||
# hash the password before saving to the database
|
||||
pwdb[username] = hashlib.sha256(f'{password}'.encode()).hexdigest()
|
||||
pwdb[username] = hash_password(password)
|
||||
return pwdb
|
||||
|
||||
def read_pwdb(pwdb_path):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue