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

Good password hashing for your software and your servers

Installation

To install bcrypt, simply:

$ pip install bcrypt

Note that bcrypt should build very easily on Linux provided you have a C compiler, headers for Python (if you’re not using pypy), and headers for the libffi libraries available on your system.

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

$ sudo apt-get install build-essential libffi-dev python-dev

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

$ sudo yum install gcc libffi-devel python-devel

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

$ apk add --update musl-dev gcc libffi-dev

Alternatives

While bcrypt remains a good 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

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

Uploaded Source

Built Distributions

bcrypt-3.2.1-cp36-abi3-win_amd64.whl (29.2 kB view details)

Uploaded CPython 3.6+ Windows x86-64

bcrypt-3.2.1-cp36-abi3-win32.whl (27.5 kB view details)

Uploaded CPython 3.6+ Windows x86

bcrypt-3.2.1-cp36-abi3-musllinux_1_1_x86_64.whl (61.7 kB view details)

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

bcrypt-3.2.1-cp36-abi3-musllinux_1_1_aarch64.whl (56.4 kB view details)

Uploaded CPython 3.6+ musllinux: musl 1.1+ ARM64

bcrypt-3.2.1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl (60.6 kB view details)

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

bcrypt-3.2.1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl (62.0 kB view details)

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

bcrypt-3.2.1-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl (54.0 kB view details)

Uploaded CPython 3.6+ manylinux: glibc 2.17+ ARM64

bcrypt-3.2.1-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl (54.5 kB view details)

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

bcrypt-3.2.1-cp36-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl (64.3 kB view details)

Uploaded CPython 3.6+ manylinux: glibc 2.12+ x86-64 manylinux: glibc 2.5+ x86-64

bcrypt-3.2.1-cp36-abi3-macosx_10_10_universal2.whl (49.7 kB view details)

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

File details

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

File metadata

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

File hashes

Hashes for bcrypt-3.2.1.tar.gz
Algorithm Hash digest
SHA256 c563f5be73303d0412367766df3860afff42f1f38583f66a2f32ab9f7966898b
MD5 bfc90e6ce9a7ed846b7ecdc1fd979c85
BLAKE2b-256 3ddca2d1751e86f3b57fb665d54113766df5067110c61622758d350f0bbbdbfa

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for bcrypt-3.2.1-cp36-abi3-win_amd64.whl
Algorithm Hash digest
SHA256 159fb1bba8c7a255e3950d85d7cdaf613b9dda6f2a856f21860e2144c1436946
MD5 a579ddb46bddce62b6fe10d982f28238
BLAKE2b-256 8f5631aec5e3d484e22b5ba347d367f4d7dac8ffd58b180154a13653fe31dffb

See more details on using hashes here.

File details

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

File metadata

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

File hashes

Hashes for bcrypt-3.2.1-cp36-abi3-win32.whl
Algorithm Hash digest
SHA256 b9dd84dd880a340675e7a59e6c326a158a56cd25e33da9f4a79e73c27c4aa7af
MD5 005349bc739dee12e6031ee5e5b6dd5c
BLAKE2b-256 db9f2c266c2f2d21076e5d6c72e03327a68730525384523ac819ee373725d83d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-3.2.1-cp36-abi3-musllinux_1_1_x86_64.whl
Algorithm Hash digest
SHA256 ae014d4de9295057ac5ea71fba81ce78e54709abf2ede301c7e9d890e6d50f82
MD5 647fbd2eae89c9d7b149eaebf4463024
BLAKE2b-256 ee90691ddb6fdb04eaf9c53e7bd500d8710729bb6f239cf410e567039219fb94

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-3.2.1-cp36-abi3-musllinux_1_1_aarch64.whl
Algorithm Hash digest
SHA256 d94bc0989171e03487540a5df7a99a3f68b27bcc77cfc5ead7954897a42eebd1
MD5 6bb6a334d312b1fc02ac61d190b59150
BLAKE2b-256 48bfdde6a08d8f81912d3863b651cec3339c17696da9a549670f1207f5bf5962

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-3.2.1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.whl
Algorithm Hash digest
SHA256 d67a5575003550797270faab95b57ac8aa1ec2341fba84efd2d12db8e2f24bac
MD5 ae237b3667e8b9f08f53cc6a365db359
BLAKE2b-256 2c661d1a6e54d27f5788543be61898125a50a3682ae4c8fda24d9d2b8f1474d7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-3.2.1-cp36-abi3-manylinux_2_17_x86_64.manylinux2014_x86_64.manylinux_2_24_x86_64.whl
Algorithm Hash digest
SHA256 b5a93a7158424174f9da34293bf6796f4f545086bd80ac1777c2390047107657
MD5 f6be0eb5839f678cb900fca1813bc69a
BLAKE2b-256 e44feede384053425bfe8a6b90765259d12bbbccebda2339928444319532d5c4

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-3.2.1-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.whl
Algorithm Hash digest
SHA256 312bf6877f151f346d10d22681a5bdcb0138ec7bcb0cb707bbbfb7ddb3659753
MD5 731edf0f106aed00a00bd7c148d4a4ee
BLAKE2b-256 586a9554fb03c224bcba8e99732a2072d9e25b49afbc2d7e668508292594d1b1

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-3.2.1-cp36-abi3-manylinux_2_17_aarch64.manylinux2014_aarch64.manylinux_2_24_aarch64.whl
Algorithm Hash digest
SHA256 bbc312297ba3914bef2b7a597e58170a4545f9437b34416c4362511977a9021c
MD5 59c42f81479d77e29e7b0844c2e4f1e2
BLAKE2b-256 abcd51e99a878c5e3f16999ef445db929933a38f5ec95bee5706bc69d15995ec

See more details on using hashes here.

File details

Details for the file bcrypt-3.2.1-cp36-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl.

File metadata

File hashes

Hashes for bcrypt-3.2.1-cp36-abi3-manylinux_2_5_x86_64.manylinux1_x86_64.manylinux_2_12_x86_64.manylinux2010_x86_64.whl
Algorithm Hash digest
SHA256 e51bbe6d2f1438d00a757ab94f5626b5e25c25dc8c6b818119a0add7dcdb152c
MD5 0bc5075d75aff02f2656e22385b16611
BLAKE2b-256 4e2d8cfdeef72810d2a2f457900a14c5c6347b3323b66f97400420f4123a867d

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for bcrypt-3.2.1-cp36-abi3-macosx_10_10_universal2.whl
Algorithm Hash digest
SHA256 0fa94ff90b070d552add1e0f3380e8e0e52d8aecff34e39724c8edee700c23bd
MD5 b727661ff433c51ede69ed2da6d41984
BLAKE2b-256 a7063b5a48ede13cdaf1dca9af056cfa9bdf5cab50cbb19b32607b9e933cfe55

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