hash password

This commit is contained in:
ASPP Student 2024-08-26 15:12:07 +03:00
parent b42ef06d91
commit 574fce85ad

View file

@ -9,11 +9,16 @@ def get_credentials():
password = getpass('Enter your password: ')
return (username, password)
def get_hash(password):
_hash = sum([ord(letter) for letter in password])
return _hash
def authenticate(username, password, pwdb):
return password == pwdb[username]
def add_user(username, pwdb):
pwdb[username] = input(f'Enter password for {username}: ')
pwd = input(f'Enter password for {username}: ')
pwdb[username] = get_hash(pwd)
return pwdb
def read_pwdb(PWDB_PATH):
@ -41,7 +46,7 @@ if __name__ == "__main__":
if username not in pwdb:
print('Wrong username!')
else:
if authenticate(username, password, pwdb):
if authenticate(username, get_hash(password), pwdb):
print('Successfully authenticated!')
else:
print('Wrong password!')