added hashing for storing passwords #10
1 changed files with 5 additions and 2 deletions
|
@ -1,6 +1,7 @@
|
|||
import getpass # hides types characters, very useful
|
||||
import json
|
||||
import sys
|
||||
from hashlib import sha256 # This library is used to create hashes out of the password
|
||||
|
||||
def get_credentials():
|
||||
username = input('Enter your username: ')
|
||||
|
@ -8,10 +9,12 @@ def get_credentials():
|
|||
return (username, password)
|
||||
|
||||
def authenticate(username, password, pwdb):
|
||||
return password == pwdb[username]
|
||||
password_hash = sha256(password.encode("utf-8")).hexdigest()
|
||||
return password_hash == pwdb[username]
|
||||
|
||||
def add_user(username, pwdb):
|
||||
pwdb[username] = getpass.getpass(f'Enter password for {username}: ')
|
||||
pwd = getpass.getpass(f'Enter password for {username}: ')
|
||||
pwdb[username] = sha256(pwd.encode("utf-8")).hexdigest()
|
||||
return pwdb
|
||||
|
||||
def read_pwdb(pwdb_path):
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue