Skip to main content

Python 3 password hashing library

Project description

Wachtwoord is a ridiculously simple Python 3 specific password hashing library. It was written as none of the existing password hashing libraries, most notably fshp, passlib, cryha and Bcryptor supported Python 3.

Supported Hashing Schemes

Currently only one specific hashing scheme is supported: PBKDF2.

Basic Usage

As Python 3 is very strict about the distinction between unicode strings and byte strings, Wachtwoord was designed to provide a uniform interface by requiring all input to be unicode strings and generating unicode strings as output exclusively.

Wachtwoord supports all the hash functions from the hashlib module. The length of the salt (default: 32) and the number of iterations (default: 10000) are configurable.

Two Modes Of Operation

Wachtwoord has two modes of operation. One where some minor initialization (that can fail) is done separately from the hashing of a password and one where both are done in one go. The former is more convenient when multiple passwords need to be hashed one after another. The other is more convenient when hashing is incidental.

Future hashing scheme extensions to Wachtwoord might make the initialization part more expensive. For the PBKDF2 scheme the difference is very small.

Separate initialization and hashing

>>> from wachtwoord.pbkdf2 import Engine
>>> engine = Engine()
>>> hash_encoded_password = engine.hash('secret_123')
>>> print(hash_encoded_password)
sha512$10000$du4/Eh0TyGLPQcluumPT6i6IkrhVV1PTP0HtiTYlqkU=$OfrLdwlMfpu38p2ffJTeM9nh1MmK2s0pWPb8L4mDdmMWG35iaX82w1sAgsjUWYGxkIMR5AHRetcpZOeTpMVRhA==
>>>
>>> is_correct_password = engine.verify('secret_123', hash_encoded_password)
>>> print(is_correct_password)
True
>>>

The Engine object allows certain parameters to be set that influence all the hashes that are subsequently generated. For instance, say we want to use the sha256 hash function instead of the default sha512 hash function:

>>> from wachtwoord.pbkdf2 import Engine
>>> engine = Engine(digestmod='sha256')
>>>

Similarly if we want to change the salt size and number of iterations we would call Engine as follows:

>>> from wachtwoord.pbkdf2 import Engine
>>> engine = Engine(digestmod='sha256', iterations=20000, salt_size=64)
>>>

Initialization and hashing in one go

>>> from wachtwoord.pbkdf2 import hash_password, verify_password
>>> hash_encoded_password = hash_password('secret_123')
>>> print(hash_encoded_password)
sha512$10000$iV430h4A94ZgFR8BLb2nyXfvcZLXPu5mxeE3y710EE8=$iT/G346H/O7jFbBaj+x184ZDAQp6VP7SAWxZyLO3lQU8k0ldH2p30oJVMDlz5Fd5gebvsWgkoGVqaMsGg3/JUw==
>>>
>>> is_correct_password = verify_password('secret_123', hash_encoded_password)
>>> print(is_correct_password)
True
>>>

The fact that the initialization and hashing happen in one go does not prevent us from changing the default values. We could have called hash_password as follows:

>>> from wachtwoord.pbkdf2 import hash_password
>>> hash_encoded_password = hash_password('secret_123', digestmod='sha256', iterations=20000, salt_size=64)

Origin of the name Wachtwoord

Wachtwoord is Dutch for password.

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

wachtwoord-0.12.tar.gz (6.1 kB view details)

Uploaded Source

File details

Details for the file wachtwoord-0.12.tar.gz.

File metadata

  • Download URL: wachtwoord-0.12.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for wachtwoord-0.12.tar.gz
Algorithm Hash digest
SHA256 ac5c9322aa71047b6fbd5124da6d3d62b9c05b0a9e2c4ba918ef0d3ec9533d6a
MD5 3f37e99dbb8ed7ed8bb0c88e2abe093f
BLAKE2b-256 8b9d83fe51ac246b95a3d2faef11df45aa7f76e5f7b774e070247bc274267d93

See more details on using hashes here.

Supported by

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