implement basic password hashing
This commit is contained in:
parent
b42ef06d91
commit
5087e36b58
10
auth.py
10
auth.py
|
@ -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:]
|
||||
return hash
|
||||
|
||||
if __name__ == "__main__":
|
||||
PWDB_PATH = 'pwdb.json'
|
||||
|
|
Loading…
Reference in a new issue