hash passwords, resolves #6
This commit is contained in:
parent
b42ef06d91
commit
29d70502e0
5
auth.py
5
auth.py
|
@ -1,19 +1,20 @@
|
||||||
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 = getpass('Enter your password: ')
|
password = hashlib.sha256(getpass('Enter your password: ').encode()).hexdigest()
|
||||||
return (username, password)
|
return (username, password)
|
||||||
|
|
||||||
def authenticate(username, password, pwdb):
|
def authenticate(username, password, pwdb):
|
||||||
return password == pwdb[username]
|
return password == pwdb[username]
|
||||||
|
|
||||||
def add_user(username, pwdb):
|
def add_user(username, pwdb):
|
||||||
pwdb[username] = input(f'Enter password for {username}: ')
|
pwdb[username] = hashlib.sha256(input(f'Enter password for {username}: ').encode()).hexdigest()
|
||||||
return pwdb
|
return pwdb
|
||||||
|
|
||||||
def read_pwdb(PWDB_PATH):
|
def read_pwdb(PWDB_PATH):
|
||||||
|
|
Loading…
Reference in a new issue