Skip to content

Increment 2 - Step 2: Auth module - #13

Merged
angelobarbu merged 2 commits into
increment-2from
increment-2-step-2
Aug 23, 2026
Merged

Increment 2 - Step 2: Auth module#13
angelobarbu merged 2 commits into
increment-2from
increment-2-step-2

Conversation

@angelobarbu

@angelobarbu angelobarbu commented Aug 23, 2026

Copy link
Copy Markdown
Owner

Increment 2 – Step 2: Auth module

The cryptographic and data-access layer for authentication: password hashing, session tokens, the role catalogue, and the repositories that persist users and sessions - built on a new libpqxx connection pool.

What's new

  • server/modules/auth (modulo_server_auth):
    • PasswordHasher - Argon2id via libsodium (crypto_pwhash_str): hash, constant-time verify, rehash detection. Cost profile is libsodium's INTERACTIVE (64 MiB, 2 passes) - above the OWASP Argon2id minimum at ~0.1 s per hash.
    • token - opaque session tokens: 32 CSPRNG bytes (libsodium) as unpadded base64url, and the SHA-256 digest (QCryptographicHash) that is the only form ever stored or compared.
    • Role - the fixed admin/user catalogue pinned to the schema ids, with name and id conversions.
    • UserRepository and SessionRepository - every method runs one transaction on a pooled connection and returns Result, never throws. A module-private pg.h owns the Qt-to-libpqxx boundary: string and bytea conversion, ISO-8601-in / epoch-milliseconds-out timestamps, and the mapping of libpqxx exceptions to stable db.* codes (auth.email_taken, auth.session_not_found layered on top).
  • ConnectionPool in server/modules/db (Qt-free): lazy connection opening, RAII leases, blocks when exhausted, discards broken connections.
  • core::validatePassword - the shared password rule (10 to 128 characters) the client will reuse for form validation.

Tests (5 new binaries)

  • Unit: hasher (round trip, unique salts, unicode, malformed hashes, rehash), token (format, uniqueness, known-answer SHA-256), roles, password policy.
  • Integration (modulo_auth_repositories_tests, opt-in via MODULO_TEST_DB_URL): pool reuse, case-insensitive email lookup, auth.email_taken with rollback, full session lifecycle, expiry, revoke-all scoping.

Notes

  • libpqxx 8 specifics handled: result[i] is a row_ref (use one_row()), pqxx::bytes is std::vector<std::byte>.
  • pg.h stays private to the auth module by design; it becomes a shared persistence module when the transactions module needs it in Increment 3.

Verified: ctest --preset all 12/12 with the database (integration suites report Skipped without it), clean -Werror build, format.sh --check green.

…r not found instead of a query error, flattened touch/revoke result handling.
@angelobarbu
angelobarbu merged commit 4f06a00 into increment-2 Aug 23, 2026
3 checks passed
@angelobarbu
angelobarbu deleted the increment-2-step-2 branch August 23, 2026 14:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant