Skip to content

Add site login with TJUPT password and two-step code - #23

Merged
tonycoder-hub merged 2 commits into
mainfrom
feat/tjupt-login
Oct 15, 2026
Merged

tonycoder-hub merged 2 commits into
mainfrom
feat/tjupt-login

Conversation

@tonycoder-hub

@tonycoder-hub tonycoder-hub commented Oct 15, 2026 •

Copy link
Copy Markdown
Owner

Summary

Until now a TJUPT session cookie had to be copied out of a browser by hand. This adds a full login flow so ptctl can issue its own session cookie from the account password and, for accounts with two-step verification, the current one-time code.

(umask 077
 jq -n --arg user "$TJUPT_USER" --rawfile password "$PASSWORD_FILE" \
   --rawfile totp <(op item get "$TJUPT_ITEM" --otp) \
   '{schema: "ptctl.credentials/v1", site_username: $user,
     site_password: ($password | rtrimstr("\n")), site_totp: ($totp | rtrimstr("\n"))}' | \
   ptctl site login --credential-bundle-stdin tjupt > "$COOKIE_FILE")
ptctl site status --cookie-stdin tjupt < "$COOKIE_FILE"

How it works

  • Site layer: new auth.login_effectful capability and site.SessionLoginer port (LoginConfig + Login), site.LoginCredentials (redacting, validated username/password/optional 4–10 digit code), and site.LoginError with fixed stop reasons.
  • httpguard: PostLoginFormOnce sends one strict HTTP/1.1 form POST with no cookie, redirect following, or retry, and captures only allowlisted live Set-Cookie values behind a redacting SessionCookie (deleted/expired values ignored; conflicting values fail closed). NewSessionCookie builds one for test doubles.
  • TJUPT: one POST to takelogin.php (username, password, logout days, plus verify_code when a code is given). Recognizes the verifyform two-step page and the failed-login page, including TJUPT's "你还有 N 次尝试机会" count. The response body is cleared after classification because the two-step page echoes the password in a hidden field. An issued access_token is kept only after a 2 s pause and one mybonus.php read that is authenticated as the same username. Declared only on the default origin.
  • CLI: ptctl site login --credential-bundle-stdin [--session-days N] SITE. Usage, session length, and stdout safety are checked before stdin is read. Stdout must be a pipe or an owner-only file (a terminal, device, or group/other-readable file is refused). Only the cookie goes to stdout; a one-line summary goes to stderr.

Deliberate public changes

  • New capability auth.login_effectful; ptctl site list now reports 9 capabilities for tjupt (was 8), and site capabilities tjupt lists it last.
  • New command site login, with usage and safety lines in ptctl help.
  • New public error lines: site login stopped: <reason> with reasons login_credentials_rejected, login_two_factor_required, login_two_factor_rejected, login_response_unrecognized, login_session_unverified, and login_request_failed, optionally suffixed with (the site reports N login attempts left before it blocks this IP); site login failed[: <fixed cause>], site login canceled, site login timed out.
  • ptctl.credentials/v1 bundles for site login take site_username, site_password, and optional site_totp. Existing bundles are unchanged; the shared decoder now supports optional fields.
  • No existing output, JSON, stop reason, exit code, site/route ID, or origin changes.

Verification

  • gofmt, go vet ./..., go test -race ./..., and go build -trimpath ./cmd/ptctl pass locally.
  • Offline tests use synthetic CANARY pages and cookies only: field order, the no-code three-field form, every refusal (body cleared, no verification read), verification mismatch/error/redirect, invalid input rejected with zero requests, no retry on transport failure, cancellation, cookie-capture allowlisting and redaction, CLI usage errors that never read stdin, exact public failure text, and unsafe-stdout refusal. The sitetest conformance suite now checks the login config and a canceled-context login.
  • Live (October 2026), through the real CLI binary:
    • Without a code: the two-step page is reported as login_two_factor_required (the site reports 10 login attempts left before it blocks this IP).
    • With a TOTP piped from 1Password: site login succeeded: site=tjupt username=<account> session_expires=<+7 days> requests=2. The cookie went to a 0600 file.
    • That issued cookie was then accepted by live site status (authenticated, same username) and site account (full snapshot).

🤖 Generated with Claude Code

jinzheng.architect and others added 2 commits October 15, 2026 21:01
Add the auth.login_effectful capability and SessionLoginer port, and a
`ptctl site login --credential-bundle-stdin [--session-days N] SITE`
command that reads site_username, site_password, and an optional
site_totp from one strict stdin bundle and writes only the new session
cookie to a pipe or owner-only stdout.

TJUPT posts the login form once with no retry, recognizes the two-step
and failed-login pages (including the site's remaining-attempts count),
clears the response body that echoes the password, and keeps the issued
access_token cookie only after one verifying mybonus.php read names the
same account. httpguard gains PostLoginFormOnce, which captures only
allowlisted live Set-Cookie values behind a redacting SessionCookie.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@tonycoder-hub
tonycoder-hub merged commit 74d08e4 into main Oct 15, 2026
5 checks passed
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