Implement simple password hashing #9
9
auth.py
9
auth.py
|
@ -10,12 +10,17 @@ def get_credentials():
|
||||||
return (username, password)
|
return (username, password)
|
||||||
|
|
||||||
def authenticate(username, password, pwdb):
|
def authenticate(username, password, pwdb):
|
||||||
return password == pwdb[username]
|
return pwhash(password) == pwdb[username]
|
||||||
|
|
||||||
def add_user(username, pwdb):
|
def add_user(username, pwdb):
|
||||||
pwdb[username] = input(f'Enter password for {username}: ')
|
password = getpass(f'Enter password for {username}: ')
|
||||||
|
pwdb[username] = pwhash(password)
|
||||||
return pwdb
|
return pwdb
|
||||||
|
|
||||||
|
def pwhash(password):
|
||||||
|
ord_password_num = [int(ord(character)) for character in password]
|
||||||
|
return sum(ord_password_num)
|
||||||
|
|
||||||
def read_pwdb(PWDB_PATH):
|
def read_pwdb(PWDB_PATH):
|
||||||
try:
|
try:
|
||||||
pwdb_file = open(PWDB_PATH, 'rt')
|
pwdb_file = open(PWDB_PATH, 'rt')
|
||||||
|
|
Loading…
Reference in a new issue