add hashing functionality
This commit is contained in:
parent
33469b8840
commit
9c71173dc3
1 changed files with 14 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
||||||
import getpass # hides types characters, very useful
|
import getpass # hides types characters, very useful
|
||||||
import json
|
import json
|
||||||
import sys
|
import sys
|
||||||
|
import hashlib #base python lib to hash strings
|
||||||
|
|
||||||
def get_credentials():
|
def get_credentials():
|
||||||
username = input('Enter your username: ')
|
username = input('Enter your username: ')
|
||||||
|
@ -8,10 +9,20 @@ def get_credentials():
|
||||||
return (username, password)
|
return (username, password)
|
||||||
|
|
||||||
def authenticate(username, password, pwdb):
|
def authenticate(username, password, pwdb):
|
||||||
return password == pwdb[username]
|
return hash_pass(password) == pwdb[username]
|
||||||
|
|
||||||
|
def hash_pass(text_password):
|
||||||
|
'''
|
||||||
|
hashes the user's string input to sha256
|
||||||
|
'''
|
||||||
|
password_in_bytes = bytearray(text_password, 'utf-8')
|
||||||
|
password_hashed = hashlib.sha256(password_in_bytes).hexdigest()
|
||||||
|
return password_hashed
|
||||||
|
|
||||||
def add_user(username, pwdb):
|
def add_user(username, pwdb):
|
||||||
pwdb[username] = getpass.getpass(f'Enter password for {username}: ')
|
password = getpass.getpass(f'Enter password for {username}: ')
|
||||||
|
password_hashed = hash_pass(password)
|
||||||
|
pwdb[username] = password_hashed
|
||||||
return pwdb
|
return pwdb
|
||||||
|
|
||||||
def read_pwdb(pwdb_path):
|
def read_pwdb(pwdb_path):
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue