Skip to main content

Modern password hashing for your software and your servers

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.1

  • Fixed the type signature on the kdf method.

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.1.tar.gz (26.1 kB view details)

Uploaded Source

Built Distributions

bcrypt-4.1.1-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl (698.3 kB view details)

Uploaded PyPy manylinux: glibc 2.28+ x86-64

bcrypt-4.1.1-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl (695.8 kB view details)

Uploaded PyPy manylinux: glibc 2.28+ ARM64

bcrypt-4.1.1-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl (698.6 kB view details)

Uploaded PyPy manylinux: glibc 2.28+ x86-64

bcrypt-4.1.1-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl (695.8 kB view details)

Uploaded PyPy manylinux: glibc 2.28+ ARM64

bcrypt-4.1.1-cp37-abi3-win_amd64.whl (158.2 kB view details)

Uploaded CPython 3.7+ Windows x86-64

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

Uploaded CPython 3.7+ Windows x86

bcrypt-4.1.1-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.1-cp37-abi3-musllinux_1_2_aarch64.whl (732.5 kB view details)

Uploaded CPython 3.7+ musllinux: musl 1.2+ ARM64

bcrypt-4.1.1-cp37-abi3-musllinux_1_1_x86_64.whl (730.2 kB view details)

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

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

Uploaded CPython 3.7+ musllinux: musl 1.1+ ARM64

bcrypt-4.1.1-cp37-abi3-manylinux_2_28_x86_64.whl (699.4 kB view details)

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

bcrypt-4.1.1-cp37-abi3-manylinux_2_28_aarch64.whl (696.3 kB view details)

Uploaded CPython 3.7+ manylinux: glibc 2.28+ ARM64

bcrypt-4.1.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (699.2 kB view details)

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

bcrypt-4.1.1-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.1-cp37-abi3-macosx_13_0_universal2.whl (528.3 kB view details)

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

bcrypt-4.1.1-cp37-abi3-macosx_10_12_universal2.whl (528.3 kB view details)

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

File details

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

File metadata

  • Download URL: bcrypt-4.1.1.tar.gz
  • Upload date:
  • Size: 26.1 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.1.tar.gz
Algorithm Hash digest
SHA256 df37f5418d4f1cdcff845f60e747a015389fa4e63703c918330865e06ad80007
MD5 77b110f937b47619cd2d1a1fd01bc118
BLAKE2b-256 df56be5fda8e6fc05123c8c9f526095e93d0802a0a0b2beaf995ee2cc20aa2f8

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-4.1.1-pp310-pypy310_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 476aa8e8aca554260159d4c7a97d6be529c8e177dbc1d443cb6b471e24e82c74
MD5 178a514c5a49e9083d7d21171b9bb171
BLAKE2b-256 9d05bab3dba6fae9c245ade63989e818010db0e703a90462505c47239f5fe697

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-4.1.1-pp310-pypy310_pp73-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 24c2ebd287b5b11016f31d506ca1052d068c3f9dc817160628504690376ff050
MD5 7cbde767726dd02e270bd7f8913b80f4
BLAKE2b-256 92abd593554eeaa05f5c4fc9dd1761d79a9f44d0f85b23e0db9f7930244a797e

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-4.1.1-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 c6450538a0fc32fb7ce4c6d511448c54c4ff7640b2ed81badf9898dcb9e5b737
MD5 e199427cd35c593fd15c52e9f15ad90b
BLAKE2b-256 994e7d8e0890d7b723da226e4136b44df044b4c7b3074e82a0fcb1a68450aeed

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-4.1.1-pp39-pypy39_pp73-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 12611c4b0a8b1c461646228344784a1089bc0c49975680a2f54f516e71e9b79e
MD5 f2b9698a113547d324f56c3fcaf30342
BLAKE2b-256 216aa6c91ab7386a0d5e40d8fe587616d6f03909fa0869ab7c0228e50eafdeec

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bcrypt-4.1.1-cp37-abi3-win_amd64.whl
  • Upload date:
  • Size: 158.2 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.1-cp37-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 14d41933510717f98aac63378b7956bbe548986e435df173c841d7f2bd0b2de7
MD5 88bcadd8aa985a23f675cc30ab2ae544
BLAKE2b-256 c6d17ea6c7e5c864decc4282ac749d1c39a04363443a7ddcbb28f0f3d3370ff8

See more details on using hashes here.

File details

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

File metadata

  • Download URL: bcrypt-4.1.1-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.1-cp37-abi3-win32.whl
Algorithm Hash digest
SHA256 3d6c4e0d6963c52f8142cdea428e875042e7ce8c84812d8e5507bd1e42534e07
MD5 b080f2ced0ba0821c5f061aa69ff83f1
BLAKE2b-256 77a9c448d7027a75083a66385a370918eb14752c629a297afbd5a3557f6f8a8c

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-4.1.1-cp37-abi3-musllinux_1_2_x86_64.whl
Algorithm Hash digest
SHA256 a7a7b8a87e51e5e8ca85b9fdaf3a5dc7aaf123365a09be7a27883d54b9a0c403
MD5 f54dbbbf1c8d1da5ca829d065114ca12
BLAKE2b-256 367c9fdf669fdc4392496818067861b2ec27c2622df4a355f9257360cb19154a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-4.1.1-cp37-abi3-musllinux_1_2_aarch64.whl
Algorithm Hash digest
SHA256 755b9d27abcab678e0b8fb4d0abdebeea1f68dd1183b3f518bad8d31fa77d8be
MD5 0bffa1d9906c492cffce40c6e1be873b
BLAKE2b-256 8e9b870624ae1deb9cc997b0530fdd45292a6f272f80e024a023d0ea9d5e02e1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-4.1.1-cp37-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 f33b385c3e80b5a26b3a5e148e6165f873c1c202423570fdf45fe34e00e5f3e5
MD5 96cb38207eaca20f36f873e7336e53a1
BLAKE2b-256 1accebf49d5d211d1ee622923c9196e6eea1274d1eecc8d00611f8b5f6f1d65a

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-4.1.1-cp37-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 2ade10e8613a3b8446214846d3ddbd56cfe9205a7d64742f0b75458c868f7492
MD5 5637d6f7177a640f1bbd735434a80b80
BLAKE2b-256 ffc0da85093fa0babf4fda1e31a1c8aab9026ee9e44539ecf706fe2a4e9391f1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-4.1.1-cp37-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 12f40f78dcba4aa7d1354d35acf45fae9488862a4fb695c7eeda5ace6aae273f
MD5 a73fcb061de0541f5b36fe6249aaa384
BLAKE2b-256 af8296ffdbe0f56b12db0da8f1a9c869399d22231ed1313a84ea2ddc6381a498

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-4.1.1-cp37-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 fb931cd004a7ad36a89789caf18a54c20287ec1cd62161265344b9c4554fdb2e
MD5 7fec00325fadea72a9ed06c74adc4064
BLAKE2b-256 c58ae7ba1562bfe80e9c480448f81118ad96087096ac9a36a57674bf8b520d69

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-4.1.1-cp37-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bab33473f973e8058d1b2df8d6e095d237c49fbf7a02b527541a86a5d1dc4444
MD5 bd07d8f4170ade6eaeb7d2efee425f3d
BLAKE2b-256 a013259124a851d361a2549560f9a3ccd286d17ef936017314a58cf7dffce8f7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-4.1.1-cp37-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 d573885b637815a7f3a3cd5f87724d7d0822da64b0ab0aa7f7c78bae534e86dc
MD5 0bf3346d8b3253ea033def22a8987751
BLAKE2b-256 038ed69af67a118aaae17a076d41b1b3f4400a66f39900b8cb72a0f918416f65

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-4.1.1-cp37-abi3-macosx_13_0_universal2.whl
Algorithm Hash digest
SHA256 2e197534c884336f9020c1f3a8efbaab0aa96fc798068cb2da9c671818b7fbb0
MD5 2ebaf7008f3a502f5e5694bd9e0a9b57
BLAKE2b-256 e8f05425ba170098cebff0a0c42b7e8ea8e5c5600fc4344cd058ef0bafc31a3e

See more details on using hashes here.

File details

Details for the file bcrypt-4.1.1-cp37-abi3-macosx_10_12_universal2.whl.

File metadata

File hashes

Hashes for bcrypt-4.1.1-cp37-abi3-macosx_10_12_universal2.whl
Algorithm Hash digest
SHA256 196008d91201bbb1aa4e666fee5e610face25d532e433a560cabb33bfdff958b
MD5 c5eab15ed57b5d5665e6f8bcac1bda42
BLAKE2b-256 7fd143bca3de2563f3385528e6267aa080ec7097858c3743aec5c2ce39ad7b54

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