add hash function
This commit is contained in:
parent
7d3a0d6bd9
commit
290926b345
8
auth.py
8
auth.py
|
@ -1,13 +1,13 @@
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
from getpass import getpass
|
from getpass import getpass
|
||||||
|
import hashlib
|
||||||
|
|
||||||
PWDB_PATH = 'pwdb.json'
|
PWDB_PATH = 'pwdb.json'
|
||||||
|
|
||||||
def get_credentials():
|
def get_credentials():
|
||||||
username = input('Enter your username: ')
|
username = input('Enter your username: ')
|
||||||
password = hash_psw(getpass('Enter your password: '))
|
password = hash_psw(getpass('Enter your password: '))
|
||||||
password = getpass('Enter your password: ')
|
|
||||||
return (username, password)
|
return (username, password)
|
||||||
|
|
||||||
def authenticate(username, password, pwdb):
|
def authenticate(username, password, pwdb):
|
||||||
|
@ -15,9 +15,13 @@ def authenticate(username, password, pwdb):
|
||||||
|
|
||||||
def add_user(username, pwdb):
|
def add_user(username, pwdb):
|
||||||
pwdb[username] = hash_psw(input(f'Enter password for {username}: '))
|
pwdb[username] = hash_psw(input(f'Enter password for {username}: '))
|
||||||
pwdb[username] = input(f'Enter password for {username}: ')
|
|
||||||
return pwdb
|
return pwdb
|
||||||
|
|
||||||
|
def hash_psw(password):
|
||||||
|
hashed_pw = hashlib.sha256(bytes(password, 'utf-8')).hexdigest()
|
||||||
|
return hashed_pw
|
||||||
|
|
||||||
|
|
||||||
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