hash passwords, resolves #6 #15

Open
adriama wants to merge 1 commit from adriama/2024-heraklion-git:hashing_6 into main

View file

@ -1,19 +1,20 @@
import json import json
import sys import sys
from getpass import getpass from getpass import getpass
import hashlib
PWDB_PATH = 'pwdb.json' PWDB_PATH = 'pwdb.json'
def get_credentials(): def get_credentials():
username = input('Enter your username: ') username = input('Enter your username: ')
password = getpass('Enter your password: ') password = hashlib.sha256(getpass('Enter your password: ').encode()).hexdigest()
return (username, password) return (username, password)
def authenticate(username, password, pwdb): def authenticate(username, password, pwdb):
return password == pwdb[username] return password == pwdb[username]
def add_user(username, pwdb): def add_user(username, pwdb):
pwdb[username] = input(f'Enter password for {username}: ') pwdb[username] = hashlib.sha256(input(f'Enter password for {username}: ').encode()).hexdigest()
return pwdb return pwdb
def read_pwdb(PWDB_PATH): def read_pwdb(PWDB_PATH):