Fast password hashing library powered by Rust
Project description
Sarhash
Fast and secure password hashing library powered by Rust with Python bindings.
Features
- 🚀 Blazing Fast: Rust-powered performance (via
sarhash-core) - 🔒 Secure: Industry-standard strength
- 🎯 Simple API: Easy-to-use Python interface
- 💪 Type Safe: Complete type hints with
.pyistubs - 📊 Password Strength: Built-in strength checking
- 🔄 Batch Operations: Efficient multi-password hashing
Installation
Prerequisites
- Python 3.11+
- Rust toolchain
- uv (recommended) or pip
Step-by-Step Setup
1. Install Rust
Sarhash uses Rust for its core implementation. Install Rust using rustup:
curl --proto '=https' --tlsv1.2 -sSf https://sh.rustup.rs | sh
After installation, restart your terminal and verify:
rustc --version
cargo --version
2. Install uv
uv is a fast Python package installer and resolver.
macOS/Linux:
curl -LsSf https://astral.sh/uv/install.sh | sh
Or using pip:
pip install uv
3. Setup Project
# Create virtual environment
uv venv --python 3.11
source .venv/bin/activate # On Windows: .venv\Scripts\activate
# Install maturin
uv pip install maturin
# Build and install
maturin develop --release
Quick Start
import sarhash
# Hash a password
hashed = sarhash.hash_password("my_secure_password")
# Verify a password
is_valid = sarhash.verify_password("my_secure_password", hashed)
print(is_valid) # True
Tutorial
Basic Usage
Hashing a Password
Hash a password using the default strong algorithm:
import sarhash
password = "user_password_123"
hashed = sarhash.hash_password(password)
print(hashed)
# Output: $argon2id$v=19$m=19456,t=2,p=1$...
Verifying a Password
To verify a password against a stored hash:
import sarhash
# Stored hash from database
stored_hash = "$argon2id$v=19$m=19456,t=2,p=1$..."
# User input
user_input = "user_password_123"
# Verify
if sarhash.verify_password(user_input, stored_hash):
print("Password is correct!")
else:
print("Invalid password")
Password Strength Checking
Check password strength before hashing:
import sarhash
password = "MyP@ssw0rd2024"
strength = sarhash.check_password_strength(password)
print(f"Score: {strength.score}/4")
print(f"Is strong: {strength.is_strong}")
print(f"Feedback: {strength.feedback}")
Batch Operations
Hash multiple passwords efficiently:
import sarhash
passwords = ["user1_pass", "user2_pass", "user3_pass"]
hashes = sarhash.hash_multiple(passwords)
for pwd, hash in zip(passwords, hashes):
print(f"{pwd} -> {hash[:50]}...")
API Reference
Core Functions
hash_password(password: str) -> str
Hash a password using the default algorithm.
Parameters:
password(str): The password to hash
Returns:
- str: The hashed password in PHC format
Raises:
ValueError: If password is empty or hashing fails
verify_password(password: str, hash: str) -> bool
Verify a password against a hash.
Parameters:
password(str): The password to verifyhash(str): The hash to verify against
Returns:
- bool:
Trueif password matches,Falseotherwise
Raises:
ValueError: If hash format is invalid
Enhanced Features
check_password_strength(password: str) -> PasswordStrength
Check password strength with detailed feedback.
Parameters:
password(str): Password to evaluate
Returns:
PasswordStrength: Object withscore(0-4),feedback(list), andis_strongproperty
hash_multiple(passwords: list[str]) -> list[str]
Hash multiple passwords efficiently.
Parameters:
passwords(list[str]): List of passwords to hash
Returns:
- list[str]: List of hashed passwords
Development
Building a Wheel Package
To build a distributable wheel package:
maturin build --release
The wheel will be created in target/wheels/.
To install the wheel:
uv pip install target/wheels/sarhash-*.whl
Development Workflow
When developing:
- Make changes to Rust code in
src/ - Rebuild:
maturin develop - Test your changes:
python examples/basic_usage.py - Run type checking:
mypy python/sarhash - Format code:
black python/
Project Structure
.
├── Cargo.toml # Rust package configuration
├── pyproject.toml # Python package configuration
├── .python-version # Python version for uv
├── src/
│ └── lib.rs # Rust implementation binding to sarhash-core
├── python/
│ └── sarhash/
│ ├── __init__.py # Python wrapper with enhanced features
│ ├── __init__.pyi # Type stubs
│ └── py.typed # PEP 561 marker
└── examples/
└── basic_usage.py # Usage examples
Security Best Practices
- Always use the latest version - Keep sarhash updated
- Never store plain text passwords - Always hash before storing
- Check password strength - Use
check_password_strength()before hashing - Use HTTPS - Always transmit passwords over encrypted connections
- Implement rate limiting - Prevent brute-force attacks
License
MIT License - see LICENSE for details.
Project details
Release history Release notifications | RSS feed
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 sarhash-0.1.0.tar.gz.
File metadata
- Download URL: sarhash-0.1.0.tar.gz
- Upload date:
- Size: 17.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
7a473d86c798e9779b50a3b13289c839c1a8cba8fa2f9d93c2bb39c968b9a482
|
|
| MD5 |
2f7d43c9a85be1fb35f06f3e80ff1bb6
|
|
| BLAKE2b-256 |
f3ad9da4ce938071f4aa35d219041e3bffa6ce088f30f819db95de1ffe96cfff
|
File details
Details for the file sarhash-0.1.0-cp311-cp311-macosx_11_0_arm64.whl.
File metadata
- Download URL: sarhash-0.1.0-cp311-cp311-macosx_11_0_arm64.whl
- Upload date:
- Size: 220.7 kB
- Tags: CPython 3.11, macOS 11.0+ ARM64
- Uploaded using Trusted Publishing? No
- Uploaded via: maturin/1.10.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0ef503c9a7d611c6b16ccd919d960e2082a05ed3eb21c7a8a8bb879d2e41ea87
|
|
| MD5 |
f511e4289ecb3891bc13d9090712e9a8
|
|
| BLAKE2b-256 |
d0b43dbd7ef6d8f55cedf93d4b7ce0e2a96ecc1ecc016964a3c2044e768196c8
|