Skip to main content

A library for password hashing and JWT encoding

Project description

Pytography

A Python library that provides secure password hashing and JSON Web Token (JWT) functionality.

Installation

pip install pytography

Quick Start

PHC String Format

The PHC (Password Hashing Competition) string format is a standardized way of representing password hashes for various algorithms. It includes all the necessary information to verify the password, including the hashing algorithm, parameters (e.g., cost factor, salt, and iteration count), and the resulting hash.

Structure

The structure of a PHC string is as follows:

  • <algorithm>: The name of the hashing algorithm used (e.g., pbkdf2, scrypt).
  • <parameters>: The specific parameters used for the algorithm, such as the cost factor, salt, and iteration count.
  • <hash>: The actual password hash.

Why Use PHC Format?

  1. Portability: The PHC format makes it easy to migrate password hashes between different systems.
  2. Security: It ensures that all relevant parameters for hashing are stored alongside the hash, including salts and iteration counts.
  3. Standardization: It provides a uniform format for representing password hashes across different hashing algorithms.

Scrypt (with PHC format)

  • scrypt: Indicates the scrypt hashing algorithm.
  • 16384: CPU/memory cost.
  • 8: Block size.
  • 32: Parallelization factor.
  • The salt and hash are base64 encoded.
  • PHC string format $scrypt$ln={n}$r={r}$p={p}${salt}${password_hash}

Pbkdf2 (with PHC format)

  • pbkdf2: Indicates the pbkdf2 hashing algorithm.
  • sha256: The hash function to use.
  • 600000: The number of iterations to use for key derivation.
  • The salt and hash are base64 encoded.
  • PHC string format $pbkdf2-{hash_name}$i={iterations}${salt}${password_hash}

Password Hashing with Scrypt (Default)

from pytography import PasswordHashLibrary

encoded_password = PasswordHashLibrary.encode(password="password", algorithm="scrypt")
is_valid = PasswordHashLibrary.verify(password="password", encoded_password=encoded_password)

Password Hashing with Pbkdf2

from pytography import PasswordHashLibrary

encoded_password = PasswordHashLibrary.encode(password="password", algorithm="pbkdf2")
is_valid = PasswordHashLibrary.verify(password="password", encoded_password=encoded_password)

JSON Web Token (JWT)

from pytography import JsonWebToken
from datetime import datetime, timedelta, UTC

now = datetime.now(UTC)
exp = (now + timedelta(seconds=7200)).timestamp()

# Create a token
token = JsonWebToken.encode(payload={"exp": exp, "user_id": 123}, key="key")

# Decode token to get payload
header, payload, signature = JsonWebToken.decode(token=token)

# Verify token
is_valid = JsonWebToken.verify(token=token, key="key")

License

This project is licensed under the terms of the LICENSE file included in the repository.

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

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

pytography-0.1.3.tar.gz (10.7 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pytography-0.1.3-py3-none-any.whl (11.5 kB view details)

Uploaded Python 3

File details

Details for the file pytography-0.1.3.tar.gz.

File metadata

  • Download URL: pytography-0.1.3.tar.gz
  • Upload date:
  • Size: 10.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for pytography-0.1.3.tar.gz
Algorithm Hash digest
SHA256 908d06c38a54110f49d21397591c19baeb57f35310903c2f87dfb7050e9b81af
MD5 130798aa609ac0c63f7bbe3c94f7433b
BLAKE2b-256 76896140b95f868f3decdb20fe53d2b20d58e7d663d40fd98baf922d4df03452

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytography-0.1.3.tar.gz:

Publisher: deploy.yml on TalentGate/pytography

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pytography-0.1.3-py3-none-any.whl.

File metadata

  • Download URL: pytography-0.1.3-py3-none-any.whl
  • Upload date:
  • Size: 11.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.0.1 CPython/3.12.8

File hashes

Hashes for pytography-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 2b89890af891447a8a520f8202709b088b6d4d478677a9595a4c7455e4d7d2ef
MD5 79bcb257e21be0079f1d8599f57d0160
BLAKE2b-256 af58a843da54e8a9f7624f7c712c296ad9bcd9f28c2809b2f063c02785938f5a

See more details on using hashes here.

Provenance

The following attestation bundles were made for pytography-0.1.3-py3-none-any.whl:

Publisher: deploy.yml on TalentGate/pytography

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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