hash_dev #10

Open
jonassc wants to merge 3 commits from jonassc/2024-heraklion-git:hash_dev into main

13
auth.py
View file

@ -10,10 +10,10 @@ def get_credentials():
return (username, password) return (username, password)
def authenticate(username, password, pwdb): def authenticate(username, password, pwdb):
return password == pwdb[username] return hash_password(password) == pwdb[username]
def add_user(username, pwdb): def add_user(username, pwdb):
pwdb[username] = input(f'Enter password for {username}: ') pwdb[username] = hash_password(input(f'Enter password for {username}: '))
return pwdb return pwdb
def read_pwdb(PWDB_PATH): def read_pwdb(PWDB_PATH):
@ -28,6 +28,15 @@ def write_pwdb(pwdb, PWDB_PATH):
pwdb_file = open(PWDB_PATH, 'wt') pwdb_file = open(PWDB_PATH, 'wt')
json.dump(pwdb, pwdb_file) json.dump(pwdb, pwdb_file)
def hash_password(password):
hash_1 = 0
for c in password.split():
hash_1 += ord(c)
hash_2 = int(log(hash_1) * 100000)
hash_3 = 1
for d in list(str(hash_2)):
hash_3 *= ord(d)
return hash_3
if __name__ == "__main__": if __name__ == "__main__":
PWDB_PATH = 'pwdb.json' PWDB_PATH = 'pwdb.json'