bcrypt
A Python library for modern password hashing, currently at version 5.0.0, with a release cadence of approximately every 6 months.
Warnings
- breaking Passing a password longer than 72 bytes to hashpw now raises a ValueError; previously, it was silently truncated.
- deprecated Support for Python 3.7 has been dropped in version 4.3.0.
- gotcha bcrypt requires a C compiler and a Rust compiler (minimum supported Rust version is 1.56.0) for building from source.
Install
-
pip install bcrypt
Imports
- bcrypt
import bcrypt
Quickstart
import bcrypt
# Hash a password
password = b"supersecret"
salt = bcrypt.gensalt()
hash = bcrypt.hashpw(password, salt)
# Check a password
if bcrypt.checkpw(password, hash):
print("Password matches")
else:
print("Password does not match")