Handle passwords longer than 72 bytes
mainPassing a password longer than 72 bytes to hashpw now raises a ValueError. To avoid this, a common pattern is to hash the password with a cryptographic hash (like sha256) and then base64 encode the digest before passing it to bcrypt.
import bcrypt
import hashlib
import base64
password = b"an incredibly long password" * 10
hashed = bcrypt.hashpw(
base64.b64encode(hashlib.sha256(password).digest()),
bcrypt.gensalt()
)