Implement sign-up, login, logout, session or token refresh and password reset for your framework, with security checks and tests.
Implement first-party authentication (users sign in with credentials your application stores) for the framework below. For delegated sign-in with a third-party provider, use an OAuth 2.0/OpenID Connect flow instead. ## Inputs Framework, version and runtime: [FRAMEWORK] Client types (server-rendered web, SPA, mobile, API clients): [CLIENTS] Session approach requested or already in use (server sessions, JWT access + refresh tokens, or undecided): [SESSION_MODEL] User store and existing user model: [USER_STORE] Requirements (email verification, MFA, account lockout, remember-me): [REQUIREMENTS] Email delivery mechanism for reset links: [EMAIL_PROVIDER] ## Instructions 1. If [SESSION_MODEL] is undecided, recommend server sessions or tokens for the listed clients and explain the tradeoff (revocation, storage, CSRF exposure). 2. Sign-up and login: hash passwords with a memory-hard algorithm following the current OWASP Password Storage guidance; compare in constant time; give the same response for unknown email and wrong password. 3. Sessions: regenerate the session identifier at login; set cookies with HttpOnly, Secure and an explicit SameSite value; add CSRF protection when cookies authenticate state-changing requests. 4. Tokens, if used: short-lived access tokens, refresh token rotation with reuse detection, and server-side revocation on logout and password change. 5. Password reset: single-use, expiring, random tokens stored as hashes; the response does not reveal whether the account exists; invalidate existing sessions after reset. 6. Throttle login and reset requests per account and per client. ## Return 1. Design summary with the session model decision. 2. Handlers for sign-up, login, logout, refresh (if tokens) and password reset request/confirm. 3. Data model changes and migrations. 4. Middleware that protects routes. 5. Tests: wrong password, unknown email, reused refresh token, expired reset token, reset token used twice, logout invalidation. 6. Remaining risks and items that need a security review. ## Acceptance checks - No plaintext passwords or reset tokens are stored or logged. - Login and reset responses do not enumerate accounts. - Cookie flags and CSRF handling are explicit. - Parameters cited for hashing name their source; do not present them as permanent. - Tests are proposed, not reported as passed.
Illustrative input and expected result. This example is a verification guide, not a recorded model run.
Content reviewed .
Framework: Express 5 on Node 22 with PostgreSQL via Prisma Clients: server-rendered web app only, same origin Session model: undecided User store: users table with id, email (unique), created_at; no password column yet Requirements: email + password, email verification, password reset; no MFA yet Email provider: existing sendEmail(to, subject, html) helper
A recommendation for server-side sessions (same-origin web app, simple revocation) with cookie flags HttpOnly, Secure and SameSite=Lax plus CSRF tokens on POST forms; a migration adding password_hash and email_verified_at and a password_reset_tokens table holding token hashes and expiry; Argon2id hashing with parameters attributed to OWASP; identical login error text for unknown email and wrong password; session regeneration at login and destruction of all user sessions after reset; and the six listed test cases. Illustrative expectation, not a recorded model run.
Ask questions or share concrete improvements.
No comments yet.
Sign in to join the discussion.
Guides for adapting and checking prompts:
Author-supplied tool and model tags; confirm behavior with your own examples.
Models