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?
- Portability: The PHC format makes it easy to migrate password hashes between different systems.
- Security: It ensures that all relevant parameters for hashing are stored alongside the hash, including salts and iteration counts.
- 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
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pytography-0.1.2.tar.gz.
File metadata
- Download URL: pytography-0.1.2.tar.gz
- Upload date:
- Size: 10.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
bac2b3cfc127547ed45ae71343eb9a6534eb8c50a5ecca676c0c97d4030cfba1
|
|
| MD5 |
7657a257046b5994ae36c3639cc6b2c6
|
|
| BLAKE2b-256 |
e3175cef91fcdaf64ac45052d55b1a2e3c8810ce8fc47c8d968a91b68f6b1a68
|
Provenance
The following attestation bundles were made for pytography-0.1.2.tar.gz:
Publisher:
deploy.yml on TalentGate/pytography
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytography-0.1.2.tar.gz -
Subject digest:
bac2b3cfc127547ed45ae71343eb9a6534eb8c50a5ecca676c0c97d4030cfba1 - Sigstore transparency entry: 154546052
- Sigstore integration time:
-
Permalink:
TalentGate/pytography@1aaea3e295f9a1e21c8d5cf404b84a8e2b025b6a -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/TalentGate
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@1aaea3e295f9a1e21c8d5cf404b84a8e2b025b6a -
Trigger Event:
release
-
Statement type:
File details
Details for the file pytography-0.1.2-py3-none-any.whl.
File metadata
- Download URL: pytography-0.1.2-py3-none-any.whl
- Upload date:
- Size: 10.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.0.1 CPython/3.12.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
dbaf1d350d1ab079682e0632cbcddf7b305ef0bbbd706aceb088c5143a69494b
|
|
| MD5 |
bdb029939cf22596783e9116b90e0b76
|
|
| BLAKE2b-256 |
097b49914ba8fce8b5ea53ffc2151ac1118891f8d8a2f4fbdb6c905300d22209
|
Provenance
The following attestation bundles were made for pytography-0.1.2-py3-none-any.whl:
Publisher:
deploy.yml on TalentGate/pytography
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pytography-0.1.2-py3-none-any.whl -
Subject digest:
dbaf1d350d1ab079682e0632cbcddf7b305ef0bbbd706aceb088c5143a69494b - Sigstore transparency entry: 154546054
- Sigstore integration time:
-
Permalink:
TalentGate/pytography@1aaea3e295f9a1e21c8d5cf404b84a8e2b025b6a -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/TalentGate
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@1aaea3e295f9a1e21c8d5cf404b84a8e2b025b6a -
Trigger Event:
release
-
Statement type: