hash_dev #10
13
auth.py
13
auth.py
|
@ -10,10 +10,10 @@ def get_credentials():
|
|||
return (username, password)
|
||||
|
||||
def authenticate(username, password, pwdb):
|
||||
return password == pwdb[username]
|
||||
return hash_password(password) == pwdb[username]
|
||||
|
||||
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
|
||||
|
||||
def read_pwdb(PWDB_PATH):
|
||||
|
@ -28,6 +28,15 @@ def write_pwdb(pwdb, PWDB_PATH):
|
|||
pwdb_file = open(PWDB_PATH, 'wt')
|
||||
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__":
|
||||
PWDB_PATH = 'pwdb.json'
|
||||
|
|
Loading…
Reference in a new issue