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

Uploaded Source

Built Distributions

bcrypt-4.0.1-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl (592.7 kB view details)

Uploaded PyPy manylinux: glibc 2.28+ x86-64

bcrypt-4.0.1-pp39-pypy39_pp73-manylinux_2_24_x86_64.whl (592.2 kB view details)

Uploaded PyPy manylinux: glibc 2.24+ x86-64

bcrypt-4.0.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (592.5 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

bcrypt-4.0.1-pp38-pypy38_pp73-manylinux_2_28_x86_64.whl (592.7 kB view details)

Uploaded PyPy manylinux: glibc 2.28+ x86-64

bcrypt-4.0.1-pp38-pypy38_pp73-manylinux_2_24_x86_64.whl (592.3 kB view details)

Uploaded PyPy manylinux: glibc 2.24+ x86-64

bcrypt-4.0.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (592.5 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

bcrypt-4.0.1-pp37-pypy37_pp73-manylinux_2_28_x86_64.whl (595.9 kB view details)

Uploaded PyPy manylinux: glibc 2.28+ x86-64

bcrypt-4.0.1-pp37-pypy37_pp73-manylinux_2_24_x86_64.whl (595.5 kB view details)

Uploaded PyPy manylinux: glibc 2.24+ x86-64

bcrypt-4.0.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (595.7 kB view details)

Uploaded PyPy manylinux: glibc 2.17+ x86-64

bcrypt-4.0.1-cp36-abi3-win_amd64.whl (152.9 kB view details)

Uploaded CPython 3.6+ Windows x86-64

bcrypt-4.0.1-cp36-abi3-win32.whl (159.4 kB view details)

Uploaded CPython 3.6+ Windows x86

bcrypt-4.0.1-cp36-abi3-musllinux_1_1_x86_64.whl (624.3 kB view details)

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

bcrypt-4.0.1-cp36-abi3-musllinux_1_1_aarch64.whl (613.1 kB view details)

Uploaded CPython 3.6+ musllinux: musl 1.1+ ARM64

bcrypt-4.0.1-cp36-abi3-manylinux_2_28_x86_64.whl (593.7 kB view details)

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

bcrypt-4.0.1-cp36-abi3-manylinux_2_28_aarch64.whl (583.6 kB view details)

Uploaded CPython 3.6+ manylinux: glibc 2.28+ ARM64

bcrypt-4.0.1-cp36-abi3-manylinux_2_24_x86_64.whl (593.2 kB view details)

Uploaded CPython 3.6+ manylinux: glibc 2.24+ x86-64

bcrypt-4.0.1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (593.5 kB view details)

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

bcrypt-4.0.1-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (583.2 kB view details)

Uploaded CPython 3.6+ manylinux: glibc 2.17+ ARM64

bcrypt-4.0.1-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl (583.0 kB view details)

Uploaded CPython 3.6+ manylinux: glibc 2.17+ ARM64 manylinux: glibc 2.24+ ARM64

bcrypt-4.0.1-cp36-abi3-macosx_10_10_universal2.whl (473.4 kB view details)

Uploaded CPython 3.6+ macOS 10.10+ universal2 (ARM64, x86-64)

File details

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

File metadata

  • Download URL: bcrypt-4.0.1.tar.gz
  • Upload date:
  • Size: 25.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.1

File hashes

Hashes for bcrypt-4.0.1.tar.gz
Algorithm Hash digest
SHA256 27d375903ac8261cfe4047f6709d16f7d18d39b1ec92aaf72af989552a650ebd
MD5 a98a2232a8e2af6980000a31ef14d48d
BLAKE2b-256 8cae3af7d006aacf513975fd1948a6b4d6f8b4a307f8a244e1a3d3774b297aad

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-4.0.1-pp39-pypy39_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 3100851841186c25f127731b9fa11909ab7b1df6fc4b9f8353f4f1fd952fbf71
MD5 f23d303c282d0fe783b6b15b1a1ad7f1
BLAKE2b-256 fb4be255df2000c2de4df524740b5f1d0a31157a1f7715b3eaf2e8f9c5c0acbb

See more details on using hashes here.

File details

Details for the file bcrypt-4.0.1-pp39-pypy39_pp73-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for bcrypt-4.0.1-pp39-pypy39_pp73-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 2b3ac11cf45161628f1f3733263e63194f22664bf4d0c0f3ab34099c02134665
MD5 5417234357e4b0ba4610a7d097cce393
BLAKE2b-256 5e01098b798dc6c6984f2d5026269e80d7cad22d6ecacd5989bdf35a9c99a03d

See more details on using hashes here.

File details

Details for the file bcrypt-4.0.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bcrypt-4.0.1-pp39-pypy39_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 705b2cea8a9ed3d55b4491887ceadb0106acf7c6387699fca771af56b1cdeeda
MD5 5388a85702aca35753402443cafb8431
BLAKE2b-256 1368f3184c1f15581ebd936125b4da04cba0995f97ecd5ee8f4262c8ebba2646

See more details on using hashes here.

File details

Details for the file bcrypt-4.0.1-pp38-pypy38_pp73-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bcrypt-4.0.1-pp38-pypy38_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b57adba8a1444faf784394de3436233728a1ecaeb6e07e8c22c8848f179b893c
MD5 c9fc4852152f4ba2978915e5bcc09758
BLAKE2b-256 418605248719aa42a4fe1ca379d45794198700e992b91d389bfaa69533fc3331

See more details on using hashes here.

File details

Details for the file bcrypt-4.0.1-pp38-pypy38_pp73-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for bcrypt-4.0.1-pp38-pypy38_pp73-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 5ad4d32a28b80c5fa6671ccfb43676e8c1cc232887759d1cd7b6f56ea4355215
MD5 aa5b2057d90432cd6972bb36f347eeb9
BLAKE2b-256 2cbe376341b47e1e3fc424c9df1af60b5aedbd5ab04f73ccdf4107e42d92ef09

See more details on using hashes here.

File details

Details for the file bcrypt-4.0.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bcrypt-4.0.1-pp38-pypy38_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 cbb03eec97496166b704ed663a53680ab57c5084b2fc98ef23291987b525cb7d
MD5 c96d8b85e41a562b099b54986f56fc33
BLAKE2b-256 772c53c17079898584306eafdc937e0c7cc1bf8e2fe17e9909716ef3f9d6555d

See more details on using hashes here.

File details

Details for the file bcrypt-4.0.1-pp37-pypy37_pp73-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bcrypt-4.0.1-pp37-pypy37_pp73-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 b3b85202d95dd568efcb35b53936c5e3b3600c7cdcc6115ba461df3a8e89f38d
MD5 73fab15bf9fd744a0f45f711766b8baf
BLAKE2b-256 28ed3c443bfbfdb37cd7c0d055b961311f49049ab4a00f45ba3bfd10d33a9443

See more details on using hashes here.

File details

Details for the file bcrypt-4.0.1-pp37-pypy37_pp73-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for bcrypt-4.0.1-pp37-pypy37_pp73-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 67a97e1c405b24f19d08890e7ae0c4f7ce1e56a712a016746c8b2d7732d65d4b
MD5 0b1b01368ab14b087e3bcc0cf74ace39
BLAKE2b-256 99a5ff4aaf2adbefb2c9808d49cec37f65e0572c4ce856b13b194fd87a6cbd14

See more details on using hashes here.

File details

Details for the file bcrypt-4.0.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bcrypt-4.0.1-pp37-pypy37_pp73-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 bf4fa8b2ca74381bb5442c089350f09a3f17797829d958fad058d6e44d9eb83c
MD5 294f1fb6af0809fb01fe442670b5605a
BLAKE2b-256 d8f643ade4d37a3319baee9aec53f636411e70c18f0e4add9cc44a18f517af5f

See more details on using hashes here.

File details

Details for the file bcrypt-4.0.1-cp36-abi3-win_amd64.whl.

File metadata

  • Download URL: bcrypt-4.0.1-cp36-abi3-win_amd64.whl
  • Upload date:
  • Size: 152.9 kB
  • Tags: CPython 3.6+, Windows x86-64
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.1

File hashes

Hashes for bcrypt-4.0.1-cp36-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 8a68f4341daf7522fe8d73874de8906f3a339048ba406be6ddc1b3ccb16fc0d9
MD5 805720053811aeb08e4b2e736089f739
BLAKE2b-256 4681d8c22cd7e5e1c6a7d48e41a1d1d46c92f17dae70a54d9814f746e6027dec

See more details on using hashes here.

File details

Details for the file bcrypt-4.0.1-cp36-abi3-win32.whl.

File metadata

  • Download URL: bcrypt-4.0.1-cp36-abi3-win32.whl
  • Upload date:
  • Size: 159.4 kB
  • Tags: CPython 3.6+, Windows x86
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.10.1

File hashes

Hashes for bcrypt-4.0.1-cp36-abi3-win32.whl
Algorithm Hash digest
SHA256 2caffdae059e06ac23fce178d31b4a702f2a3264c20bfb5ff541b338194d8fab
MD5 a6f775387cf764a2406798647a3c124c
BLAKE2b-256 aaca6a534669890725cbb8c1fb4622019be31813c8edaa7b6d5b62fc9360a17e

See more details on using hashes here.

File details

Details for the file bcrypt-4.0.1-cp36-abi3-musllinux_1_1_x86_64.whl.

File metadata

File hashes

Hashes for bcrypt-4.0.1-cp36-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 e9a51bbfe7e9802b5f3508687758b564069ba937748ad7b9e890086290d2f79e
MD5 96248cfa4b34974c6044d44a08a57f2e
BLAKE2b-256 8769edacb37481d360d06fc947dab5734aaf511acb7d1a1f9e2849454376c0f8

See more details on using hashes here.

File details

Details for the file bcrypt-4.0.1-cp36-abi3-musllinux_1_1_aarch64.whl.

File metadata

File hashes

Hashes for bcrypt-4.0.1-cp36-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 089098effa1bc35dc055366740a067a2fc76987e8ec75349eb9484061c54f535
MD5 8581896676ed32a5ac4f4caf88abef76
BLAKE2b-256 dd4f3632a69ce344c1551f7c9803196b191a8181c6a1ad2362c225581ef0d383

See more details on using hashes here.

File details

Details for the file bcrypt-4.0.1-cp36-abi3-manylinux_2_28_x86_64.whl.

File metadata

File hashes

Hashes for bcrypt-4.0.1-cp36-abi3-manylinux_2_28_x86_64.whl
Algorithm Hash digest
SHA256 ca3204d00d3cb2dfed07f2d74a25f12fc12f73e606fcaa6975d1f7ae69cacbb2
MD5 5fb2c3f2022f68d7b614beecd2db2c8b
BLAKE2b-256 64feda28a5916128d541da0993328dc5cf4b43dfbf6655f2c7a2abe26ca2dc88

See more details on using hashes here.

File details

Details for the file bcrypt-4.0.1-cp36-abi3-manylinux_2_28_aarch64.whl.

File metadata

File hashes

Hashes for bcrypt-4.0.1-cp36-abi3-manylinux_2_28_aarch64.whl
Algorithm Hash digest
SHA256 fbdaec13c5105f0c4e5c52614d04f0bca5f5af007910daa8b6b12095edaa67b3
MD5 3150624604a287f583caf0752a17f60b
BLAKE2b-256 fba7ee4561fd9b78ca23c8e5591c150cc58626a5dfb169345ab18e1c2c664ee0

See more details on using hashes here.

File details

Details for the file bcrypt-4.0.1-cp36-abi3-manylinux_2_24_x86_64.whl.

File metadata

File hashes

Hashes for bcrypt-4.0.1-cp36-abi3-manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 a522427293d77e1c29e303fc282e2d71864579527a04ddcfda6d4f8396c6c36a
MD5 5563ae703f8e59b16299877f13665b3f
BLAKE2b-256 7d50e683d8418974a602ba40899c8a5c38b3decaf5a4d36c32fc65dce454d8a8

See more details on using hashes here.

File details

Details for the file bcrypt-4.0.1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl.

File metadata

File hashes

Hashes for bcrypt-4.0.1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 ae88eca3024bb34bb3430f964beab71226e761f51b912de5133470b649d82344
MD5 adea5eef68b95f4666b2909bcf81608a
BLAKE2b-256 aa48fd2b197a9741fa790ba0b88a9b10b5e88e62ff5cf3e1bc96d8354d7ce613

See more details on using hashes here.

File details

Details for the file bcrypt-4.0.1-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl.

File metadata

File hashes

Hashes for bcrypt-4.0.1-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 0eaa47d4661c326bfc9d08d16debbc4edf78778e6aaba29c1bc7ce67214d4410
MD5 f39d80694970fe52294afbf854fddee1
BLAKE2b-256 411649ff5146fb815742ad58cafb5034907aa7f166b1344d0ddd7fd1c818bd17

See more details on using hashes here.

File details

Details for the file bcrypt-4.0.1-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl.

File metadata

File hashes

Hashes for bcrypt-4.0.1-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 08d2947c490093a11416df18043c27abe3921558d2c03e2076ccb28a116cb6d0
MD5 d80523b2b32be79ab3448e7985aa3658
BLAKE2b-256 ec0a1582790232fef6c2aa201f345577306b8bfe465c2c665dec04c86a016879

See more details on using hashes here.

File details

Details for the file bcrypt-4.0.1-cp36-abi3-macosx_10_10_universal2.whl.

File metadata

File hashes

Hashes for bcrypt-4.0.1-cp36-abi3-macosx_10_10_universal2.whl
Algorithm Hash digest
SHA256 b1023030aec778185a6c16cf70f359cbb6e0c289fd564a7cfa29e727a1c38f8f
MD5 e09c9331d2e2dd37fd4f39b440e1310d
BLAKE2b-256 78d43b2657bd58ef02b23a07729b0df26f21af97169dbd0b5797afa9e97ebb49

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