Last active
March 12, 2018 02:49
-
-
Save ivanleoncz/6b60a933df17d982637ed40f786804f9 to your computer and use it in GitHub Desktop.
Determining validation of password, against password hash.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/python3 | |
""" Determining validation of a password, against its hash. """ | |
import bcrypt | |
from getpass import getpass | |
# simulation of hashed password stored in a DBMS (MongoDB, MySQL, SQLite, etc.) | |
salt = bcrypt.gensalt() | |
db_password = "Guido*Py2017".encode('utf-8') | |
db_pass_hash = bcrypt.hashpw(db_password,salt) | |
# receiving password and generating a hash, using the password hash from the DBMS as salt | |
# info: the salt value is stored at the beggining of the password hash | |
password = getpass(prompt="Please, insert the password: ").encode('utf-8') | |
pass_hash = bcrypt.hashpw(password,db_pass_hash) | |
print("\n- Password Hash (DBMS): ",db_pass_hash) | |
print("- Password Hash (Input):",pass_hash) | |
if pass_hash == db_pass_hash: | |
print("\nLogin Successful!") | |
else: | |
print("\nWrong Password!") |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment