authentication-system-example

A set of example patterns for adding user login, registration, sessions, and protected pages to an application.

In plain words
What is it for?
Use it when designing or reviewing sign-up, login, logout, session, and access-control flows.
Why use it?
It gives authentication code a consistent structure and highlights security-related steps such as password hashing, token handling, and secure cookies.

Cursor rule for Cursor

Install

Getting it into your agent

One page per mod, every tool's command on it. A separate URL per tool would split the same page into five that compete with each other.

agentmods
npx agentmods add rules/hansonli05/cursor-rules-system/authentication-system-example
Clone the repo
git clone --depth 1 https://github.com/Hansonli05/Cursor-rules-system

Made for: Cursor.

Per session 5 Only the description is in the session, so the agent can decide to use it. The body loads when it is invoked.
When invoked 1,392 The whole file, excluding the scripts and references it only reads on demand.
Security scan A 0 findings. Scan, not verified.
Origin original No closer match found in the catalogue.
Token cost

What it costs to keep this loaded

Counted locally with the o200k_base tokenizer, which is exact for GPT models; Claude uses its own tokenizer and its counts differ. Treat this as one consistent yardstick across the catalogue rather than a bill. Prices are per million input tokens.

ModelPer sessionOnce invoked
Fable 5 $0.00005 $0.01392
Opus 5 $0.00003 $0.00696
Sonnet 5 $0.00001 $0.00278
Haiku 4.5 $0.00001 $0.00139

Measured yesterday against content hash b5fc116dc8bc, method: parsed. Prices are Anthropic first-party input rates as of 2026-08-30, from the pricing page.

Security

Grade A, and why

authentication-system-example scanned grade A with 0 findings against 26 rules in 11 categories — prompt injection, anti-refusal, data exfiltration, privilege escalation, supply chain, agent snooping, system-prompt leakage, SSRF and excessive agency — measured yesterday.

A static scan of the body, not an audit. Every finding is printed with the line that produced it so you can judge whether it matters here. A mod is markdown that instructs an agent; that is exactly why what it instructs is worth reading.

Nothing flagged

None of the 26 patterns this scan looks for appear in this file: no shell pipes, no recursive deletes, no credential paths, no hidden text, no instruction-override or anti-refusal phrasing, no agent-config snooping. That is not a guarantee, it is the absence of the things that are checkable.

.cursor/rules/feature-rules/authentication-system-example.mdc · 226 lines

How it starts

The opening of the file, as written. The whole thing — 226 lines — stays where its author put it; the contents beside it link to each section on GitHub.

Authentication System (Example)

Summary

Defines patterns for implementing user authentication including login, signup, session management, and protected routes. This is an example template - customize for your specific authentication needs.

Context

Authentication is a critical system that requires consistent patterns for security, user experience, and maintainability. This rule ensures all authentication-related code follows established patterns.

Instructions

Authentication Flow

  1. User Registration

    • Collect required user information
    • Validate input data (email format, password strength)
    • Check for existing accounts
    • Create user record with hashed password
    • Send verification email (if required)
    • Auto-login or redirect to login
  2. User Login

    • Validate credentials
    • Generate secure session token/JWT
    • Set secure HTTP-only cookies
    • Redirect to intended destination
    • Handle "remember me" functionality
  3. Session Management

    • Validate tokens on protected routes
    • Refresh tokens before expiration
    • Handle logout (clear tokens/cookies)
    • Manage concurrent sessions

Security Patterns

  • Password Hashing: Use bcrypt or similar secure hashing
  • Token Security: Use JWT with proper expiration and signing
  • HTTPS Only: All authentication requests over HTTPS
  • Rate Limiting: Prevent brute force attacks
  • Input Validation: Sanitize all user inputs
  • CSRF Protection: Implement CSRF tokens for forms

Protected Routes

// Pattern for protected route middleware
function requireAuth(handler: RouteHandler) {
  return async (req, res) => {
    const token = extractTokenFromRequest(req);
    
    if (!token) {
      return res.status(401).json({ error: 'Authentication required' });
    }
    
    try {
      const user = await validateToken(token);
      req.user = user;
      return handler(req, res);
    } catch (error) {
      return res.status(401).json({ error: 'Invalid token' });
    }
  };
}

Read the full file on GitHub · 226 lines

Changes

What this file has done since we first saw it

Hashed on every crawl. A supply-chain change to an agent config is a question of when, not whether, so the history is kept rather than the latest state alone.

  1. yesterday First seen · 226 lines · 5 tokens per session scan A b5fc116dc8bc

Subscribe to this mod's changes

authentication-system-example is a cursor rule published in the GitHub repository Hansonli05/Cursor-rules-system (2 stars, last pushed 1y ago), licensed MIT. It adds 5 tokens to every session and 1,392 once invoked, about $0.0000 per session on Opus 5. A static security scan graded it A with 0 findings. No closer match exists in the catalogue, so it is treated as the original; first seen 2026-08-31.