Skip to main content

Modern password hashing for your software and your servers

Reason this release was yanked:

Incompatibility with assumptions made by passlib.

Project description

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

bcrypt-4.1.0.tar.gz (26.0 kB view details)

Uploaded Source

Built Distributions

bcrypt-4.1.0-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl (697.9 kB view details)

Uploaded PyPy manylinux: glibc 2.28+ x86-64

bcrypt-4.1.0-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl (695.2 kB view details)

Uploaded PyPy manylinux: glibc 2.28+ ARM64

bcrypt-4.1.0-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl (698.0 kB view details)

Uploaded PyPy manylinux: glibc 2.28+ x86-64

bcrypt-4.1.0-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl (695.2 kB view details)

Uploaded PyPy manylinux: glibc 2.28+ ARM64

bcrypt-4.1.0-cp37-abi3-win_amd64.whl (158.3 kB view details)

Uploaded CPython 3.7+ Windows x86-64

bcrypt-4.1.0-cp37-abi3-win32.whl (171.2 kB view details)

Uploaded CPython 3.7+ Windows x86

bcrypt-4.1.0-cp37-abi3-musllinux_1_2_x86_64.whl (750.1 kB view details)

Uploaded CPython 3.7+ musllinux: musl 1.2+ x86-64

bcrypt-4.1.0-cp37-abi3-musllinux_1_2_aarch64.whl (732.4 kB view details)

Uploaded CPython 3.7+ musllinux: musl 1.2+ ARM64

bcrypt-4.1.0-cp37-abi3-musllinux_1_1_x86_64.whl (730.1 kB view details)

Uploaded CPython 3.7+ musllinux: musl 1.1+ x86-64

bcrypt-4.1.0-cp37-abi3-musllinux_1_1_aarch64.whl (725.9 kB view details)

Uploaded CPython 3.7+ musllinux: musl 1.1+ ARM64

bcrypt-4.1.0-cp37-abi3-manylinux_2_28_x86_64.whl (699.3 kB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.28+ x86-64

bcrypt-4.1.0-cp37-abi3-manylinux_2_28_aarch64.whl (696.2 kB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.28+ ARM64

bcrypt-4.1.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (699.1 kB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ x86-64

bcrypt-4.1.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (696.0 kB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.17+ ARM64

bcrypt-4.1.0-cp37-abi3-macosx_13_0_universal2.whl (528.2 kB view details)

Uploaded CPython 3.7+ macOS 13.0+ universal2 (ARM64, x86-64)

File details

Details for the file bcrypt-4.1.0.tar.gz.

File metadata

  • Download URL: bcrypt-4.1.0.tar.gz
  • Upload date:
  • Size: 26.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for bcrypt-4.1.0.tar.gz
Algorithm Hash digest
SHA256 8807681e040e89ee3201249a7849342748e643b4bb2749dfc8dd1b34f6baa349
MD5 b921669391579c944596f5a1b709de5f
BLAKE2b-256 68721e9a905561a3aa824658d6deb09f48012cc3bfd433cf039593c47026a9aa

See more details on using hashes here.

File details

Details for the file bcrypt-4.1.0-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bcrypt-4.1.0-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 d068ba10dfaf5ea7260cf703109f77350043b7efe58d6d6e4027694e8144989f
MD5 afaca6e6a12966ecf19d5422d4f42fc1
BLAKE2b-256 2d09c0b6f2c2cd4507d49ba802c38092212185b76f87a402a85adfad2cd951ee

See more details on using hashes here.

File details

Details for the file bcrypt-4.1.0-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for bcrypt-4.1.0-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 4d9330d165e0079a32e998d0e1dfab00ada7062070b759ab793c3331ab7e9d78
MD5 06e7d59ec518d6496a90ca12b3bf13ec
BLAKE2b-256 9e85655196ff3e3d8a3826462c77130236b0030382f49383149563910eb39e4c

See more details on using hashes here.

File details

Details for the file bcrypt-4.1.0-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bcrypt-4.1.0-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 4417aa6c0701b8c20136d845198555f61e23d1ee64a8c33a13a9f2d6b6ed531c
MD5 a27f21ce48b6f09d9397da6ebe105f05
BLAKE2b-256 872cecb600323a54acfec46869229810cd5c3eb486b84be2d9b6e041062b37b7

See more details on using hashes here.

File details

Details for the file bcrypt-4.1.0-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for bcrypt-4.1.0-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 e16655bfe3077223d8b8e00c81a6d21b78b9b47a20b57a052e26c8ec4cdc7613
MD5 408d0c54c9a71f014475bcd4e3b70423
BLAKE2b-256 fe2eddd706bd94bc477fb76b9de8b2b1dd19214af27a297fe931f99ed8552813

See more details on using hashes here.

File details

Details for the file bcrypt-4.1.0-cp37-abi3-win_amd64.whl.

File metadata

  • Download URL: bcrypt-4.1.0-cp37-abi3-win_amd64.whl
  • Upload date:
  • Size: 158.3 kB
  • Tags: CPython 3.7+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for bcrypt-4.1.0-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 15b9865d3fb52d30c8301f13ab074006dbacc219539470f93c13fd720cdc1558
MD5 927e94479f46c307ab121e49a501a61c
BLAKE2b-256 2727c9f3cb31987c5a48b86fa033f01d796d3ef403059366a822e2269a3e4dc7

See more details on using hashes here.

File details

Details for the file bcrypt-4.1.0-cp37-abi3-win32.whl.

File metadata

  • Download URL: bcrypt-4.1.0-cp37-abi3-win32.whl
  • Upload date:
  • Size: 171.2 kB
  • Tags: CPython 3.7+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.12.0

File hashes

Hashes for bcrypt-4.1.0-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 69740306830e26479a15e3686027aae67b2250e2a973b3f303bcabc1eb224f77
MD5 44889c244638d3b0653b5dcadf1211fe
BLAKE2b-256 a01592dc7868630643e3ebf0227a74d905bdf271438b38f4a5d7f46ef146a9ee

See more details on using hashes here.

File details

Details for the file bcrypt-4.1.0-cp37-abi3-musllinux_1_2_x86_64.whl.

File metadata

File hashes

Hashes for bcrypt-4.1.0-cp37-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 81458aac2577582e22d9d2682a457992827472ba5010e9e77431317dfe804c98
MD5 fc45c1ed3d99d354afda1ae4de399ed2
BLAKE2b-256 87ef6a28e56eba576913710247fc81f8b04678d3a8679d0e4949ef516e5ce240

See more details on using hashes here.

File details

Details for the file bcrypt-4.1.0-cp37-abi3-musllinux_1_2_aarch64.whl.

File metadata

File hashes

Hashes for bcrypt-4.1.0-cp37-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 adb15ff096c9cfdb1b152a5c032f1d4f7390eabd98fd27b0d789c536ef9e7b40
MD5 ae28480ec73116ecee5d61c61c6fa0c6
BLAKE2b-256 c0a73b89f65fee46491c8cebe92aaef3140a96ba1c6e35c4dfd4baa2e829f4ea

See more details on using hashes here.

File details

Details for the file bcrypt-4.1.0-cp37-abi3-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for bcrypt-4.1.0-cp37-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 544a13c2555027d1042d249ba0e3a302cba105224420f06d20e61179207a7e02
MD5 dae81a076df1050b962457997d305e0b
BLAKE2b-256 d639c3022ec17bf47e723a66858d2fe0ea92ccf0bdb326887459d34d24e95ebb

See more details on using hashes here.

File details

Details for the file bcrypt-4.1.0-cp37-abi3-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for bcrypt-4.1.0-cp37-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 b5dea889347e80dbd86442b989128e12812b181a40ae4db496388ad36a8fe2b7
MD5 6c669c45f0235f600d20412ed68b26f2
BLAKE2b-256 6319f1c1d889509de38d286d2c6e5e8479b49b4696c27e5a6753131ce5673669

See more details on using hashes here.

File details

Details for the file bcrypt-4.1.0-cp37-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bcrypt-4.1.0-cp37-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 30be7a77166a97f85ec2a94100e9841ea97c38ca5a93335111fe96cd485ba250
MD5 9aec29f9112e40819143141366c2cdc7
BLAKE2b-256 fc11515a17bf9c397ed9dedd41ff3f4d644a5c766a4294777a59e7991920643c

See more details on using hashes here.

File details

Details for the file bcrypt-4.1.0-cp37-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for bcrypt-4.1.0-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 8d9151b2098bf5598954a5d731c66c4e84321d3f4b9f167d4b73084df6d3958d
MD5 e082c7d809880ab9a8454fcd18032f6d
BLAKE2b-256 01b12c3dd9ad9769c07e174655d590d8fceb06e27a9bb1264c2be9e0b9b5159c

See more details on using hashes here.

File details

Details for the file bcrypt-4.1.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bcrypt-4.1.0-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 6e86108bd26137c5acb86fdf5696a30433c7e9e6a81e3aef6c3746cb9ac535a8
MD5 564f22fc381a40aae3c15417bbc88e2c
BLAKE2b-256 a9f5c539ba92ee980942b55161e9d59a7fe9aa843657e61e4e4ea259ca638f24

See more details on using hashes here.

File details

Details for the file bcrypt-4.1.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for bcrypt-4.1.0-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 9e8e085b188827087bcda882a2ca14843164cde43d83aca02a67b94ed68b8d1f
MD5 42794a518210dc304457b187526d2d35
BLAKE2b-256 9e0480f7120d3d53f9953a0136f011e38aee9d6f5be143c3f6c16752e0ca5771

See more details on using hashes here.

File details

Details for the file bcrypt-4.1.0-cp37-abi3-macosx_13_0_universal2.whl.

File metadata

File hashes

Hashes for bcrypt-4.1.0-cp37-abi3-macosx_13_0_universal2.whl
Algorithm Hash digest
SHA256 a601e52d0318142d1de84ab213ae062a10168c1acd721a2125bcf97d8646809b
MD5 9015846f9b4ae6fb80d4d42e4e0623bf
BLAKE2b-256 a371c488d45a3deed0b387a07042efab7b095eb56947d958e4dd23d8c4b2593e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page