tet.sqlalchemy.password module

Password hashing mixin for SQLAlchemy user models.

This module provides a mixin class that adds secure password handling to SQLAlchemy models using bcrypt hashing.

Example

Creating a user model with password support:

from sqlalchemy import Column, Integer, String
from sqlalchemy.ext.declarative import declarative_base
from tet.sqlalchemy.password import UserPasswordMixin

Base = declarative_base()

class User(UserPasswordMixin, Base):
    __tablename__ = "users"

    id = Column(Integer, primary_key=True)
    username = Column(String(100), unique=True, nullable=False)

Using the password property:

user = User(username="john")
user.password = "secret123"  # Automatically hashed

# Later, validate password
if user.validate_password("secret123"):
    print("Password correct!")
class tet.sqlalchemy.password.UserPasswordMixin[source]

Bases: object

Mixin that adds password hashing to SQLAlchemy user models.

Provides a password property that automatically hashes on set, and a validate_password() method for verification.

password = <Synonym at 0x7d99aed78520; no key>
validate_password(password)[source]

Validate a plaintext password against the stored hash.

Parameters:

password – Plaintext password to validate

Returns:

True if password matches, False otherwise