add hashing functionality #14
1 changed files with 14 additions and 3 deletions
|
@ -1,6 +1,7 @@
|
|||
import getpass # hides types characters, very useful
|
||||
import json
|
||||
import sys
|
||||
import hashlib #base python lib to hash strings
|
||||
|
||||
def get_credentials():
|
||||
username = input('Enter your username: ')
|
||||
|
@ -8,11 +9,21 @@ def get_credentials():
|
|||
return (username, password)
|
||||
|
||||
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):
|
||||
pwdb[username] = getpass.getpass(f'Enter password for {username}: ')
|
||||
return pwdb
|
||||
password = getpass.getpass(f'Enter password for {username}: ')
|
||||
password_hashed = hash_pass(password)
|
||||
pwdb[username] = password_hashed
|
||||
return pwdb
|
||||
|
||||
def read_pwdb(pwdb_path):
|
||||
try:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue