Skip to main content

starspring-security

PyPI Python License: MIT

Standalone password hashing utilities for any Python web framework.

Works with StarSpring, FastAPI, Flask, Django, or any Python project.


Installation

Choose the algorithm you need:

# BCrypt (recommended — default)
pip install starspring-security[bcrypt]

# Argon2 (modern, memory-hard)
pip install starspring-security[argon2]

# Both
pip install starspring-security[all]

Quick Start

from starspring_security import BCryptPasswordEncoder

encoder = BCryptPasswordEncoder()

# Hash a password
hashed = encoder.encode("my_secret_password")

# Verify a password
encoder.matches("my_secret_password", hashed)   # True
encoder.matches("wrong_password", hashed)        # False

Encoders

BCrypt is slow by design — making brute-force attacks expensive. Automatically salts every password.

from starspring_security import BCryptPasswordEncoder

encoder = BCryptPasswordEncoder()          # Default: rounds=12
encoder = BCryptPasswordEncoder(rounds=14) # Stronger (slower)

hashed = encoder.encode("password")
encoder.matches("password", hashed)  # True

Argon2PasswordEncoder ✅ Modern

Winner of the Password Hashing Competition (2015). More resistant to GPU attacks than BCrypt due to memory hardness.

from starspring_security import Argon2PasswordEncoder

encoder = Argon2PasswordEncoder()
hashed = encoder.encode("password")
encoder.matches("password", hashed)  # True

# Custom parameters
encoder = Argon2PasswordEncoder(time_cost=3, memory_cost=65536, parallelism=2)

Sha256PasswordEncoder ⚠️ Deprecated

SHA-256 is not recommended for passwords — it is too fast and vulnerable to brute-force attacks. Use BCrypt or Argon2 instead.

Included for legacy/migration purposes only. Raises a DeprecationWarning.

from starspring_security import Sha256PasswordEncoder

encoder = Sha256PasswordEncoder()  # ⚠️ DeprecationWarning raised
hashed = encoder.encode("password")
encoder.matches("password", hashed)  # True

Framework Examples

StarSpring

from starspring import Service, Transactional
from starspring_security import BCryptPasswordEncoder

encoder = BCryptPasswordEncoder()

@Service
class UserService:
    def __init__(self, user_repo):
        self.user_repo = user_repo

    @Transactional
    async def register(self, username: str, password: str):
        user = User(username=username, password=encoder.encode(password))
        return await self.user_repo.save(user)

    async def authenticate(self, username: str, password: str):
        user = await self.user_repo.find_by_username(username)
        if user and encoder.matches(password, user.password):
            return user
        return None

FastAPI

from fastapi import FastAPI, HTTPException
from starspring_security import BCryptPasswordEncoder

app = FastAPI()
encoder = BCryptPasswordEncoder()

@app.post("/register")
def register(username: str, password: str):
    hashed = encoder.encode(password)
    # save to DB...

@app.post("/login")
def login(username: str, password: str):
    user = get_user(username)  # from DB
    if not encoder.matches(password, user.password):
        raise HTTPException(status_code=401, detail="Invalid credentials")

Flask

from flask import Flask
from starspring_security import BCryptPasswordEncoder

app = Flask(__name__)
encoder = BCryptPasswordEncoder()

@app.route("/register", methods=["POST"])
def register():
    hashed = encoder.encode(request.form["password"])
    # save to DB...

@app.route("/login", methods=["POST"])
def login():
    user = get_user(request.form["username"])
    if not encoder.matches(request.form["password"], user.password):
        return "Invalid credentials", 401

Django

from starspring_security import BCryptPasswordEncoder

encoder = BCryptPasswordEncoder()

# In your view or service
def create_user(username, password):
    hashed = encoder.encode(password)
    User.objects.create(username=username, password=hashed)

def authenticate(username, password):
    user = User.objects.get(username=username)
    return encoder.matches(password, user.password)

Algorithm Comparison

BCrypt Argon2 SHA-256
Recommended ✅ Yes ✅ Yes ❌ No
Auto-salted ✅ Yes ✅ Yes ✅ Yes (in this lib)
Brute-force resistant ✅ Yes ✅ Yes ❌ No
GPU resistant ⚠️ Partial ✅ Yes ❌ No
Extra dependency bcrypt argon2-cffi None

License

MIT — see LICENSE

Metadata

Release files for starspring-security 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for starspring-security 0.1.1
File Size Uploaded Provenance Actions
starspring_security-0.1.1.tar.gz 5.8 kB Without provenance Details for starspring_security-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for starspring-security 0.1.1
File Interpreter ABI Platform Actions
starspring_security-0.1.1-py3-none-any.whl Python 3 none any Details for starspring_security-0.1.1-py3-none-any.whl

Total release size: 12.3 kB

Release files / starspring_security-0.1.1.tar.gz

Download URL starspring_security-0.1.1.tar.gz
Size 5.8 kB
Tags Source
SHA-256 checksum
How to use checksums
5df149e47da8aa6b428bab3b61b532d2a145a67a310084cb37fc7503c030fcc1
BLAKE2b-256 checksum
How to use checksums
dc7c08d7671bd328ae4f931e0d1e9f65ae770481c83c409a98caedef31e2c93b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.26.6 CPython/3.14.2 Windows/11

Release files / starspring_security-0.1.1-py3-none-any.whl

Download URL starspring_security-0.1.1-py3-none-any.whl
Size 6.4 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3743b5a7af828c52d167b75704bc6a07d85c79359faef71b5e02c4d1cf2ee93f
BLAKE2b-256 checksum
How to use checksums
f81e40fa555796d2aa02b83a18b63fb684ed568cb1f33de985cf80389577130b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via pdm/2.26.6 CPython/3.14.2 Windows/11

Security for starspring-security 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page