implement basic password hashing #11

Open
giovannife wants to merge 1 commit from giovannife/2024-heraklion-git:pwd-hash into main
Showing only changes of commit 5087e36b58 - Show all commits

10
auth.py
View file

@ -10,10 +10,11 @@ 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}: ')
password = input(f'Enter password for {username}: ')
pwdb[username] = pwhash(password)
return pwdb
def read_pwdb(PWDB_PATH):
@ -28,6 +29,11 @@ def write_pwdb(pwdb, PWDB_PATH):
pwdb_file = open(PWDB_PATH, 'wt')
json.dump(pwdb, pwdb_file)
def pwhash(password):
hash = ''
for letter in password:
hash += hex(ord(letter)**2)[2:]
Review

what's the [2:] about?

what's the `[2:]` about?
return hash
if __name__ == "__main__":
PWDB_PATH = 'pwdb.json'