{"id":343,"library":"bcrypt","title":"bcrypt","description":"A Python library for modern password hashing, currently at version 5.0.0, with a release cadence of approximately every 6 months.","status":"active","version":"5.0.0","language":"python","source_language":"en","source_url":"https://github.com/pyca/bcrypt","tags":["security","password hashing","cryptography"],"install":[{"cmd":"pip install bcrypt","lang":"bash","label":"Install bcrypt"}],"dependencies":[{"reason":"Provides cryptographic recipes and primitives; required for bcrypt functionality.","package":"cryptography"}],"imports":[{"note":"Ensure 'bcrypt' is imported directly; avoid 'from bcrypt import *' to prevent namespace pollution.","symbol":"bcrypt","correct":"import bcrypt"}],"quickstart":{"code":"import bcrypt\n\n# Hash a password\npassword = b\"supersecret\"\nsalt = bcrypt.gensalt()\nhash = bcrypt.hashpw(password, salt)\n\n# Check a password\nif bcrypt.checkpw(password, hash):\n    print(\"Password matches\")\nelse:\n    print(\"Password does not match\")","lang":"python","description":"A simple example demonstrating how to hash and check passwords using bcrypt."},"warnings":[{"fix":"Ensure passwords are 72 bytes or shorter before hashing.","message":"Passing a password longer than 72 bytes to hashpw now raises a ValueError; previously, it was silently truncated.","severity":"breaking","affected_versions":"5.0.0"},{"fix":"Upgrade to Python 3.8 or later.","message":"Support for Python 3.7 has been dropped in version 4.3.0.","severity":"deprecated","affected_versions":"4.3.0"},{"fix":"Install the necessary compilers or use pre-built wheels.","message":"bcrypt requires a C compiler and a Rust compiler (minimum supported Rust version is 1.56.0) for building from source.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-05-12T13:11:22.879Z","next_check":"2026-09-28T00:00:00.000Z","problems":[{"fix":"Install the library using pip: `pip install bcrypt` or `python -m pip install bcrypt`","cause":"The 'bcrypt' library is not installed in the Python environment being used, or the Python interpreter cannot find it.","error":"ModuleNotFoundError: No module named 'bcrypt'"},{"fix":"Ensure that the stored hash is retrieved correctly without alteration and that both the plaintext password and the stored hash are consistently encoded (e.g., `password.encode('utf-8')`) before being passed to `bcrypt.checkpw()`.","cause":"This error typically occurs during password verification (`bcrypt.checkpw()`) when the provided hash is malformed, corrupted, or not a valid bcrypt hash, often due to incorrect storage, retrieval, or encoding.","error":"ValueError: Invalid salt"},{"fix":"Encode the password string to bytes before passing it to `bcrypt` functions: `password_string.encode('utf-8')`","cause":"The `bcrypt` library functions like `bcrypt.hashpw()` and `bcrypt.checkpw()` require byte strings (e.g., `b'password'`) as input for passwords and hashes, but a Unicode string (Python's default `str` type) was provided.","error":"TypeError: Unicode-objects must be encoded before hashing"},{"fix":"Ensure that passwords do not exceed 72 bytes in length. If longer passwords are required, pre-hash them with another cryptographic hash function (e.g., SHA-256) and then pass the base64-encoded output of that hash to `bcrypt.hashpw()`.","cause":"The bcrypt algorithm, as specified, only processes the first 72 bytes of a password. Since version 5.0.0 of the Python `bcrypt` library, providing a password longer than 72 bytes explicitly raises this `ValueError` instead of silently truncating it.","error":"ValueError: Password too long"}],"ecosystem":"pypi","meta_description":null,"install_score":80,"install_tag":"verified","quickstart_score":80,"quickstart_tag":"verified","pypi_latest":null,"install_checks":{"last_tested":"2026-05-12","tag":"verified","tag_description":"installs cleanly on critical runtimes, fast import, recently tested","results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"18.6M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"19M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"20.4M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"21M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"12.3M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"13M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"11.9M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"18.1M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"default","exit_code":0,"wheel_type":null,"failure_reason":null,"install_time_s":null,"import_time_s":0,"mem_mb":0,"disk_size":"18M"}]},"quickstart_checks":{"last_tested":"2026-04-23","tag":"verified","tag_description":"quickstart runs on critical runtimes, recently tested","results":[{"runtime":"python:3.10-alpine","exit_code":0},{"runtime":"python:3.10-slim","exit_code":0},{"runtime":"python:3.11-alpine","exit_code":0},{"runtime":"python:3.11-slim","exit_code":0},{"runtime":"python:3.12-alpine","exit_code":0},{"runtime":"python:3.12-slim","exit_code":0},{"runtime":"python:3.13-alpine","exit_code":0},{"runtime":"python:3.13-slim","exit_code":0},{"runtime":"python:3.9-alpine","exit_code":0},{"runtime":"python:3.9-slim","exit_code":0}]}}