Skip to content

Instantly share code, notes, and snippets.

@Tarequzzaman
Last active May 23, 2022 12:45
Show Gist options
  • Save Tarequzzaman/ef776136a8b8c646f52f7755c984ef7b to your computer and use it in GitHub Desktop.
Save Tarequzzaman/ef776136a8b8c646f52f7755c984ef7b to your computer and use it in GitHub Desktop.
Password Encryption(bcrypt) & Checking
#------------------- Requirements ------------------------
pip install bcrypt
#------------------- Hashing Password ---------------------
import bcrypt
passwd = b'xyz123'
salt = bcrypt.gensalt()
hashed = bcrypt.hashpw(passwd, b'$2b$12$q1zbtH7i5oA8N1ZnkisNm.')
print(salt)
print(hashed)
#store the hash value on your database
#----------------- Checking -----------------------------------
import bcrypt
#get the hash value from your database then cheeck
passwd = b'xyz123'
if bcrypt.checkpw(passwd, hashed): #make sure you convert the hash in byte format
print("match")
else:
print("does not match")
#----------------------- END -----------------------------------
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment