hashed-psw #14
10
auth.py
10
auth.py
|
@ -1,21 +1,27 @@
|
|||
import json
|
||||
import sys
|
||||
from getpass import getpass
|
||||
import hashlib
|
||||
|
||||
PWDB_PATH = 'pwdb.json'
|
||||
|
||||
def get_credentials():
|
||||
username = input('Enter your username: ')
|
||||
password = getpass('Enter your password: ')
|
||||
password = hash_psw(getpass('Enter your password: '))
|
||||
return (username, password)
|
||||
|
||||
def authenticate(username, password, pwdb):
|
||||
return password == pwdb[username]
|
||||
|
||||
def add_user(username, pwdb):
|
||||
pwdb[username] = input(f'Enter password for {username}: ')
|
||||
pwdb[username] = hash_psw(input(f'Enter password for {username}: '))
|
||||
return pwdb
|
||||
|
||||
def hash_psw(password):
|
||||
hashed_pw = hashlib.sha256(bytes(password, 'utf-8')).hexdigest()
|
||||
return hashed_pw
|
||||
|
||||
|
||||
def read_pwdb(PWDB_PATH):
|
||||
try:
|
||||
pwdb_file = open(PWDB_PATH, 'rt')
|
||||
|
|
Loading…
Reference in a new issue