Implement hashlib password hashing; print hashpass
This commit is contained in:
parent
b42ef06d91
commit
0cb4e35299
7
auth.py
7
auth.py
|
@ -1,6 +1,7 @@
|
||||||
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'
|
||||||
|
|
||||||
|
@ -16,6 +17,11 @@ def add_user(username, pwdb):
|
||||||
pwdb[username] = input(f'Enter password for {username}: ')
|
pwdb[username] = input(f'Enter password for {username}: ')
|
||||||
return pwdb
|
return pwdb
|
||||||
|
|
||||||
|
def pwhash(password):
|
||||||
|
byte_pass = bytes(password, 'UTF-8')
|
||||||
|
hashed_password = hashlib.sha256()
|
||||||
|
hashed_password.update(byte_pass)
|
||||||
|
return print(hashed_password.digest())
|
||||||
def read_pwdb(PWDB_PATH):
|
def read_pwdb(PWDB_PATH):
|
||||||
try:
|
try:
|
||||||
pwdb_file = open(PWDB_PATH, 'rt')
|
pwdb_file = open(PWDB_PATH, 'rt')
|
||||||
|
@ -45,4 +51,5 @@ if __name__ == "__main__":
|
||||||
print('Successfully authenticated!')
|
print('Successfully authenticated!')
|
||||||
else:
|
else:
|
||||||
print('Wrong password!')
|
print('Wrong password!')
|
||||||
|
pwhash(password)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue