Last active
May 23, 2022 12:45
-
-
Save Tarequzzaman/ef776136a8b8c646f52f7755c984ef7b to your computer and use it in GitHub Desktop.
Password Encryption(bcrypt) & Checking
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
#------------------- 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