Skip to content

Instantly share code, notes, and snippets.

@ivanleoncz
Last active March 12, 2018 02:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ivanleoncz/6b60a933df17d982637ed40f786804f9 to your computer and use it in GitHub Desktop.
Save ivanleoncz/6b60a933df17d982637ed40f786804f9 to your computer and use it in GitHub Desktop.
Determining validation of password, against password hash.
#!/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