#!/usr/bin/env python
import bcrypt
passwd = b's$cret12'
salt = bcrypt.gensalt()
hashed = bcrypt.hashpw(passwd, salt)
if bcrypt.checkpw(passwd, hashed):
print("match")
else:
print("does not match")
# requires pip install bcrypt
import bcrypt
passwd = b's$cret40$'
# generate a random salt default is 12 rounds
salt = bcrypt.gensalt()
# one way hash encryption
hashed = bcrypt.hashpw(passwd, salt)
# print salt and hash passwd
print(salt)
print(hashed)
# output
# b'$2b$12$d3s7Dzm0r1X.xnpUBEB0qe'
# b'$2b$12$d3s7Dzm0r1X.xnpUBEB0qemgMAErbJW7NXDEH3nEmYd5hXpNXRw9y'
# generate a random salt default is 20 rounds
# the more rounds to encrypt the longer the encryption process will take
salt = bcrypt.gensalt(20)
# one way hash encryption
hashed = bcrypt.hashpw(passwd, salt)
# print salt and hash passwd
print(salt)
print(hashed)
# output
# b'$2b$14$fZXSvkUH8cIvMxmAetZy7O'
# b'$2b$14$fZXSvkUH8cIvMxmAetZy7Od42hj0.rOoAtr/3GGjLyDqn.pKPsCRi'