Skip to main content
Yanked

This release has been yanked by its maintainers, and will be ignored by installers, except when explicitly specified.
Consider using release 5.0.0 instead.
Reason given by maintainers: Incompatibility with assumptions made by passlib.

bcrypt

Latest Version https://github.com/pyca/bcrypt/workflows/CI/badge.svg?branch=main

Acceptable password hashing for your software and your servers (but you should really use argon2id or scrypt)

Installation

To install bcrypt, simply:

$ pip install bcrypt

Note that bcrypt should build very easily on Linux provided you have a C compiler and a Rust compiler (the minimum supported Rust version is 1.56.0).

For Debian and Ubuntu, the following command will ensure that the required dependencies are installed:

$ sudo apt-get install build-essential cargo

For Fedora and RHEL-derivatives, the following command will ensure that the required dependencies are installed:

$ sudo yum install gcc cargo

For Alpine, the following command will ensure that the required dependencies are installed:

$ apk add --update musl-dev gcc cargo

Alternatives

While bcrypt remains an acceptable choice for password storage, depending on your specific use case you may also want to consider using scrypt (either via standard library or cryptography) or argon2id via argon2_cffi.

Changelog

4.1.0

  • Dropped support for Python 3.6.

  • Bumped MSRV to 1.64. (Note: Rust 1.63 can be used by setting the BCRYPT_ALLOW_RUST_163 environment variable)

4.0.1

  • We now build PyPy manylinux wheels.

  • Fixed a bug where passing an invalid salt to checkpw could result in a pyo3_runtime.PanicException. It now correctly raises a ValueError.

4.0.0

  • bcrypt is now implemented in Rust. Users building from source will need to have a Rust compiler available. Nothing will change for users downloading wheels.

  • We no longer ship manylinux2010 wheels. Users should upgrade to the latest pip to ensure this doesn’t cause issues downloading wheels on their platform. We now ship manylinux_2_28 wheels for users on new enough platforms.

  • NUL bytes are now allowed in inputs.

3.2.2

  • Fixed packaging of py.typed files in wheels so that mypy works.

3.2.1

  • Added support for compilation on z/OS

  • The next release of bcrypt with be 4.0 and it will require Rust at compile time, for users building from source. There will be no additional requirement for users who are installing from wheels. Users on most platforms will be able to obtain a wheel by making sure they have an up to date pip. The minimum supported Rust version will be 1.56.0.

  • This will be the final release for which we ship manylinux2010 wheels. Going forward the minimum supported manylinux ABI for our wheels will be manylinux2014. The vast majority of users will continue to receive manylinux wheels provided they have an up to date pip.

3.2.0

  • Added typehints for library functions.

  • Dropped support for Python versions less than 3.6 (2.7, 3.4, 3.5).

  • Shipped abi3 Windows wheels (requires pip >= 20).

3.1.7

  • Set a setuptools lower bound for PEP517 wheel building.

  • We no longer distribute 32-bit manylinux1 wheels. Continuing to produce them was a maintenance burden.

3.1.6

  • Added support for compilation on Haiku.

3.1.5

  • Added support for compilation on AIX.

  • Dropped Python 2.6 and 3.3 support.

  • Switched to using abi3 wheels for Python 3. If you are not getting a wheel on a compatible platform please upgrade your pip version.

3.1.4

  • Fixed compilation with mingw and on illumos.

3.1.3

  • Fixed a compilation issue on Solaris.

  • Added a warning when using too few rounds with kdf.

3.1.2

  • Fixed a compile issue affecting big endian platforms.

  • Fixed invalid escape sequence warnings on Python 3.6.

  • Fixed building in non-UTF8 environments on Python 2.

3.1.1

  • Resolved a UserWarning when used with cffi 1.8.3.

3.1.0

  • Added support for checkpw, a convenience method for verifying a password.

  • Ensure that you get a $2y$ hash when you input a $2y$ salt.

  • Fixed a regression where $2a hashes were vulnerable to a wraparound bug.

  • Fixed compilation under Alpine Linux.

3.0.0

  • Switched the C backend to code obtained from the OpenBSD project rather than openwall.

  • Added support for bcrypt_pbkdf via the kdf function.

2.0.0

  • Added support for an adjustible prefix when calling gensalt.

  • Switched to CFFI 1.0+

Usage

Password Hashing

Hashing and then later checking that a password matches the previous hashed password is very simple:

>>> import bcrypt
>>> password = b"super secret password"
>>> # Hash a password for the first time, with a randomly-generated salt
>>> hashed = bcrypt.hashpw(password, bcrypt.gensalt())
>>> # Check that an unhashed password matches one that has previously been
>>> # hashed
>>> if bcrypt.checkpw(password, hashed):
...     print("It Matches!")
... else:
...     print("It Does not Match :(")

KDF

As of 3.0.0 bcrypt now offers a kdf function which does bcrypt_pbkdf. This KDF is used in OpenSSH’s newer encrypted private key format.

>>> import bcrypt
>>> key = bcrypt.kdf(
...     password=b'password',
...     salt=b'salt',
...     desired_key_bytes=32,
...     rounds=100)

Adjustable Work Factor

One of bcrypt’s features is an adjustable logarithmic work factor. To adjust the work factor merely pass the desired number of rounds to bcrypt.gensalt(rounds=12) which defaults to 12):

>>> import bcrypt
>>> password = b"super secret password"
>>> # Hash a password for the first time, with a certain number of rounds
>>> hashed = bcrypt.hashpw(password, bcrypt.gensalt(14))
>>> # Check that a unhashed password matches one that has previously been
>>> #   hashed
>>> if bcrypt.checkpw(password, hashed):
...     print("It Matches!")
... else:
...     print("It Does not Match :(")

Adjustable Prefix

Another one of bcrypt’s features is an adjustable prefix to let you define what libraries you’ll remain compatible with. To adjust this, pass either 2a or 2b (the default) to bcrypt.gensalt(prefix=b"2b") as a bytes object.

As of 3.0.0 the $2y$ prefix is still supported in hashpw but deprecated.

Maximum Password Length

The bcrypt algorithm only handles passwords up to 72 characters, any characters beyond that are ignored. To work around this, a common approach is to hash a password with a cryptographic hash (such as sha256) and then base64 encode it to prevent NULL byte problems before hashing the result with bcrypt:

>>> password = b"an incredibly long password" * 10
>>> hashed = bcrypt.hashpw(
...     base64.b64encode(hashlib.sha256(password).digest()),
...     bcrypt.gensalt()
... )

Compatibility

This library should be compatible with py-bcrypt and it will run on Python 3.6+, and PyPy 3.

C Code

This library uses code from OpenBSD.

Security

bcrypt follows the same security policy as cryptography, if you identify a vulnerability, we ask you to contact us privately.

Release files for bcrypt 4.1.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bcrypt 4.1.0
File Size Uploaded
bcrypt-4.1.0.tar.gz 26.0 kB Details

Built distributions (wheels)

Table of built distributions (wheels) for bcrypt 4.1.0
File
bcrypt-4.1.0-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl PyPy 3.10 PyPy 3.10 7.3 Linux glibc 2.28+ x86-64 Details
bcrypt-4.1.0-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl PyPy 3.10 PyPy 3.10 7.3 Linux glibc 2.28+ ARM64 Details
bcrypt-4.1.0-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl PyPy 3.9 PyPy 3.9 7.3 Linux glibc 2.28+ x86-64 Details
bcrypt-4.1.0-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl PyPy 3.9 PyPy 3.9 7.3 Linux glibc 2.28+ ARM64 Details
bcrypt-4.1.0-cp37-abi3-win_amd64.whl CPython 3.7 abi3 Windows x86-64 Details
bcrypt-4.1.0-cp37-abi3-win32.whl CPython 3.7 abi3 Windows x86-32 Details
bcrypt-4.1.0-cp37-abi3-musllinux_1_2_x86_64.whl CPython 3.7 abi3 Linux musl 1.2+ x86-64 Details
bcrypt-4.1.0-cp37-abi3-musllinux_1_2_aarch64.whl CPython 3.7 abi3 Linux musl 1.2+ ARM64 Details
bcrypt-4.1.0-cp37-abi3-musllinux_1_1_x86_64.whl CPython 3.7 abi3 Linux musl 1.1+ x86-64 Details
bcrypt-4.1.0-cp37-abi3-musllinux_1_1_aarch64.whl CPython 3.7 abi3 Linux musl 1.1+ ARM64 Details
bcrypt-4.1.0-cp37-abi3-manylinux_2_28_x86_64.whl CPython 3.7 abi3 Linux glibc 2.28+ x86-64 Details
bcrypt-4.1.0-cp37-abi3-manylinux_2_28_aarch64.whl CPython 3.7 abi3 Linux glibc 2.28+ ARM64 Details
bcrypt-4.1.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl CPython 3.7 abi3 Linux glibc 2.17+ x86-64 Details
bcrypt-4.1.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl CPython 3.7 abi3 Linux glibc 2.17+ ARM64 Details
bcrypt-4.1.0-cp37-abi3-macosx_13_0_universal2.whl CPython 3.7 abi3 macOS 13.0+ universal2 (ARM64, x86-64) Details

Total release size: 9.4 MB

Release files / bcrypt-4.1.0.tar.gz

Download URL bcrypt-4.1.0.tar.gz
Size 26.0 kB
Tags Source
SHA-256 checksum
How to use checksums
8807681e040e89ee3201249a7849342748e643b4bb2749dfc8dd1b34f6baa349
BLAKE2b-256 checksum
How to use checksums
68721e9a905561a3aa824658d6deb09f48012cc3bfd433cf039593c47026a9aa
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / bcrypt-4.1.0-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl

Download URL bcrypt-4.1.0-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl
Size 697.9 kB
Tags Linux glibc 2.28+ x86-64 PyPy 3.10 PyPy 3.10 7.3
SHA-256 checksum
How to use checksums
d068ba10dfaf5ea7260cf703109f77350043b7efe58d6d6e4027694e8144989f
BLAKE2b-256 checksum
How to use checksums
2d09c0b6f2c2cd4507d49ba802c38092212185b76f87a402a85adfad2cd951ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / bcrypt-4.1.0-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl

Download URL bcrypt-4.1.0-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl
Size 695.2 kB
Tags Linux glibc 2.28+ ARM64 PyPy 3.10 PyPy 3.10 7.3
SHA-256 checksum
How to use checksums
4d9330d165e0079a32e998d0e1dfab00ada7062070b759ab793c3331ab7e9d78
BLAKE2b-256 checksum
How to use checksums
9e85655196ff3e3d8a3826462c77130236b0030382f49383149563910eb39e4c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / bcrypt-4.1.0-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl

Download URL bcrypt-4.1.0-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl
Size 698.0 kB
Tags Linux glibc 2.28+ x86-64 PyPy 3.9 PyPy 3.9 7.3
SHA-256 checksum
How to use checksums
4417aa6c0701b8c20136d845198555f61e23d1ee64a8c33a13a9f2d6b6ed531c
BLAKE2b-256 checksum
How to use checksums
872cecb600323a54acfec46869229810cd5c3eb486b84be2d9b6e041062b37b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / bcrypt-4.1.0-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl

Download URL bcrypt-4.1.0-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl
Size 695.2 kB
Tags Linux glibc 2.28+ ARM64 PyPy 3.9 PyPy 3.9 7.3
SHA-256 checksum
How to use checksums
e16655bfe3077223d8b8e00c81a6d21b78b9b47a20b57a052e26c8ec4cdc7613
BLAKE2b-256 checksum
How to use checksums
fe2eddd706bd94bc477fb76b9de8b2b1dd19214af27a297fe931f99ed8552813
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / bcrypt-4.1.0-cp37-abi3-win_amd64.whl

Download URL bcrypt-4.1.0-cp37-abi3-win_amd64.whl
Size 158.3 kB
Tags CPython 3.7 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
15b9865d3fb52d30c8301f13ab074006dbacc219539470f93c13fd720cdc1558
BLAKE2b-256 checksum
How to use checksums
2727c9f3cb31987c5a48b86fa033f01d796d3ef403059366a822e2269a3e4dc7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / bcrypt-4.1.0-cp37-abi3-win32.whl

Download URL bcrypt-4.1.0-cp37-abi3-win32.whl
Size 171.2 kB
Tags CPython 3.7 Windows x86-32 abi3
SHA-256 checksum
How to use checksums
69740306830e26479a15e3686027aae67b2250e2a973b3f303bcabc1eb224f77
BLAKE2b-256 checksum
How to use checksums
a01592dc7868630643e3ebf0227a74d905bdf271438b38f4a5d7f46ef146a9ee
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / bcrypt-4.1.0-cp37-abi3-musllinux_1_2_x86_64.whl

Download URL bcrypt-4.1.0-cp37-abi3-musllinux_1_2_x86_64.whl
Size 750.1 kB
Tags CPython 3.7 Linux musl 1.2+ x86-64 abi3
SHA-256 checksum
How to use checksums
81458aac2577582e22d9d2682a457992827472ba5010e9e77431317dfe804c98
BLAKE2b-256 checksum
How to use checksums
87ef6a28e56eba576913710247fc81f8b04678d3a8679d0e4949ef516e5ce240
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / bcrypt-4.1.0-cp37-abi3-musllinux_1_2_aarch64.whl

Download URL bcrypt-4.1.0-cp37-abi3-musllinux_1_2_aarch64.whl
Size 732.4 kB
Tags CPython 3.7 Linux musl 1.2+ ARM64 abi3
SHA-256 checksum
How to use checksums
adb15ff096c9cfdb1b152a5c032f1d4f7390eabd98fd27b0d789c536ef9e7b40
BLAKE2b-256 checksum
How to use checksums
c0a73b89f65fee46491c8cebe92aaef3140a96ba1c6e35c4dfd4baa2e829f4ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / bcrypt-4.1.0-cp37-abi3-musllinux_1_1_x86_64.whl

Download URL bcrypt-4.1.0-cp37-abi3-musllinux_1_1_x86_64.whl
Size 730.1 kB
Tags CPython 3.7 Linux musl 1.1+ x86-64 abi3
SHA-256 checksum
How to use checksums
544a13c2555027d1042d249ba0e3a302cba105224420f06d20e61179207a7e02
BLAKE2b-256 checksum
How to use checksums
d639c3022ec17bf47e723a66858d2fe0ea92ccf0bdb326887459d34d24e95ebb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / bcrypt-4.1.0-cp37-abi3-musllinux_1_1_aarch64.whl

Download URL bcrypt-4.1.0-cp37-abi3-musllinux_1_1_aarch64.whl
Size 725.9 kB
Tags CPython 3.7 Linux musl 1.1+ ARM64 abi3
SHA-256 checksum
How to use checksums
b5dea889347e80dbd86442b989128e12812b181a40ae4db496388ad36a8fe2b7
BLAKE2b-256 checksum
How to use checksums
6319f1c1d889509de38d286d2c6e5e8479b49b4696c27e5a6753131ce5673669
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / bcrypt-4.1.0-cp37-abi3-manylinux_2_28_x86_64.whl

Download URL bcrypt-4.1.0-cp37-abi3-manylinux_2_28_x86_64.whl
Size 699.3 kB
Tags CPython 3.7 Linux glibc 2.28+ x86-64 abi3
SHA-256 checksum
How to use checksums
30be7a77166a97f85ec2a94100e9841ea97c38ca5a93335111fe96cd485ba250
BLAKE2b-256 checksum
How to use checksums
fc11515a17bf9c397ed9dedd41ff3f4d644a5c766a4294777a59e7991920643c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / bcrypt-4.1.0-cp37-abi3-manylinux_2_28_aarch64.whl

Download URL bcrypt-4.1.0-cp37-abi3-manylinux_2_28_aarch64.whl
Size 696.2 kB
Tags CPython 3.7 Linux glibc 2.28+ ARM64 abi3
SHA-256 checksum
How to use checksums
8d9151b2098bf5598954a5d731c66c4e84321d3f4b9f167d4b73084df6d3958d
BLAKE2b-256 checksum
How to use checksums
01b12c3dd9ad9769c07e174655d590d8fceb06e27a9bb1264c2be9e0b9b5159c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / bcrypt-4.1.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl

Download URL bcrypt-4.1.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Size 699.1 kB
Tags CPython 3.7 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
6e86108bd26137c5acb86fdf5696a30433c7e9e6a81e3aef6c3746cb9ac535a8
BLAKE2b-256 checksum
How to use checksums
a9f5c539ba92ee980942b55161e9d59a7fe9aa843657e61e4e4ea259ca638f24
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / bcrypt-4.1.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl

Download URL bcrypt-4.1.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Size 696.0 kB
Tags CPython 3.7 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
9e8e085b188827087bcda882a2ca14843164cde43d83aca02a67b94ed68b8d1f
BLAKE2b-256 checksum
How to use checksums
9e0480f7120d3d53f9953a0136f011e38aee9d6f5be143c3f6c16752e0ca5771
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release files / bcrypt-4.1.0-cp37-abi3-macosx_13_0_universal2.whl

Download URL bcrypt-4.1.0-cp37-abi3-macosx_13_0_universal2.whl
Size 528.2 kB
Tags CPython 3.7 abi3 macOS 13.0+ universal2 (ARM64, x86-64)
SHA-256 checksum
How to use checksums
a601e52d0318142d1de84ab213ae062a10168c1acd721a2125bcf97d8646809b
BLAKE2b-256 checksum
How to use checksums
a371c488d45a3deed0b387a07042efab7b095eb56947d958e4dd23d8c4b2593e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.2 CPython/3.12.0

Release history Release notifications | RSS feed

5.0.0

63 release files

4.3.0

51 release files

4.2.1

25 release files

4.2.0

27 release files

4.1.2

27 release files

4.1.1

17 release files

This release

4.1.0 This release

16 release files

4.0.0

12 release files

3.2.0

10 release files

3.1.7

19 release files

3.1.6

19 release files

3.1.5

19 release files

3.1.4

34 release files

3.1.3

36 release files

3.1.2

36 release files

3.1.1

31 release files

3.1.0

31 release files

3.0.0

30 release files

2.0.0

13 release files

1.1.1

11 release files

1.0.2

1 release file

1.0.1

1 release file

1.0.0

1 release file

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page