implemented password hashing #13
1 changed files with 9 additions and 2 deletions
|
@ -2,16 +2,23 @@ import getpass # hides types characters, very useful
|
|||
import json
|
||||
import sys
|
||||
|
||||
def naive_hashing_function(password):
|
||||
sum=0
|
||||
password = str(password)
|
||||
for x in [ord(c) for c in password]:
|
||||
sum+=x**2
|
||||
return sum
|
||||
|
||||
def get_credentials():
|
||||
username = input('Enter your username: ')
|
||||
password = getpass.getpass('Enter your password: ')
|
||||
return (username, password)
|
||||
|
||||
def authenticate(username, password, pwdb):
|
||||
return password == pwdb[username]
|
||||
return naive_hashing_function(password) == pwdb[username]
|
||||
|
||||
def add_user(username, pwdb):
|
||||
pwdb[username] = getpass.getpass(f'Enter password for {username}: ')
|
||||
pwdb[username] = naive_hashing_function(getpass.getpass(f'Enter password for {username}: '))
|
||||
return pwdb
|
||||
|
||||
def read_pwdb(pwdb_path):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue