← Home ← Codex ← DEBT
Browse by Category
+ added · updated 7d
← Back to glossary

Authentication

Security PHP 7.0+ Intermediate
debt(d8/e6/b7/t7)
d8 Detectability Operational debt — how invisible misuse is to your safety net

Closest to 'silent in production until users hit it' (d9), slightly better at d8 because SAST tools and security scanners (no detection_hints provided, but category-appropriate tools like Psalm taint analysis, SonarQube security rules) can flag weak hashing like MD5, but missing session_regenerate_id, missing rate limiting, and missing cookie flags are typically silent in production until exploited.

e6 Effort Remediation debt — work required to fix once spotted

Closest to 'cross-cutting refactor across the codebase' (e7), slightly better at e6 because while quick_fix lists single-call swaps (password_hash, session_regenerate_id), in practice fixing authentication touches the login flow, registration, password reset, session config, and rate limiting middleware — multiple files across the auth subsystem.

b7 Burden Structural debt — long-term weight of choosing wrong

Closest to 'strong gravitational pull' (b7), because authentication applies across web and CLI contexts and every protected endpoint depends on the auth model; changing the hashing algorithm or session strategy ripples through the entire application.

t7 Trap Cognitive debt — how counter-intuitive correct behaviour is

Closest to 'serious trap' (t7), grounded in the misconception field: developers reasonably believe storing a user ID in $_SESSION is sufficient, but the working-but-exploitable nature (missing cookie_secure, cookie_httponly, session_regenerate_id, timeout) is a classic case where the obvious implementation looks correct and passes tests but is broken in adversarial conditions.

About DEBT scoring →

Also Known As

auth login user authentication sign in credential validation authn

TL;DR

The process of verifying that a user is who they claim to be — typically by validating credentials (password, token, certificate) and establishing a session or issuing a signed token for subsequent requests.

Explanation

Authentication answers 'who is this user?' — distinct from authorisation ('what can they do?'). PHP authentication typically uses one of three mechanisms: session-based (credentials validated, user ID stored in a server-side session, session ID sent as a cookie); token-based (JWT or opaque token issued on login, sent in Authorization header on subsequent requests, validated server-side); or OAuth/OIDC (delegated to a third party like Google, GitHub, or an identity provider). Critical implementation requirements: passwords must be hashed with password_hash() using PASSWORD_ARGON2ID or PASSWORD_BCRYPT (never MD5 or SHA); login forms must use HTTPS; brute-force protection (rate limiting, account lockout) must be in place; session IDs must be regenerated on privilege change (session_regenerate_id(true)) to prevent session fixation. Laravel Sanctum handles API token authentication; Laravel Breeze/Jetstream handle session-based authentication.

Common Misconception

Storing the user ID in a session is all that is needed for authentication. Session-based authentication requires several additional security controls: the session must be started over HTTPS only (session.cookie_secure = true), the session cookie must be HTTP-only (session.cookie_httponly = true) to prevent JavaScript access, the session ID must be regenerated after login to prevent session fixation attacks, and the session must have a reasonable timeout. Missing any of these produces a working but exploitable authentication system.

Why It Matters

Authentication is the gateway to every protected resource in a PHP application. Mistakes in authentication implementation — weak password hashing, missing session regeneration, no brute-force protection, HTTP-only cookies absent — translate directly into account takeovers, data breaches, and credential stuffing attacks. The most common PHP authentication vulnerability is not using prepared statements in the credential check query (SQL injection bypass) or using MD5 for password hashing (crackable in seconds on a GPU). Both are easily avoided with password_hash() and PDO.

Common Mistakes

  • Using MD5 or SHA-1 for password hashing — use password_hash($pass, PASSWORD_ARGON2ID) exclusively.
  • Not regenerating the session ID after login — session_regenerate_id(true) prevents session fixation attacks.
  • Missing brute-force protection — without rate limiting, an attacker can try millions of passwords against any login endpoint.
  • Storing plaintext passwords or reversibly encrypted passwords — if the database is compromised, all passwords are exposed immediately.

Code Examples

✗ Vulnerable
// MD5 hashing + no session regeneration + SQL injection
$hash = md5($_POST['password']); // crackable in seconds
$user = $db->query("SELECT * FROM users WHERE email='{$_POST['email']}'
    AND password='$hash'"); // SQL injectable
if ($user) {
    $_SESSION['user_id'] = $user['id'];
    // No session_regenerate_id — session fixation possible
}
✓ Fixed
// Secure authentication
$stmt = $pdo->prepare('SELECT * FROM users WHERE email = ?');
$stmt->execute([$_POST['email']]);
$user = $stmt->fetch();

if ($user && password_verify($_POST['password'], $user['password_hash'])) {
    session_regenerate_id(true); // prevent session fixation
    $_SESSION['user_id'] = $user['id'];
    $_SESSION['logged_in_at'] = time();
    // Redirect — never re-display login form on success
    header('Location: /dashboard');
    exit;
}

Added 23 Mar 2026
Edited 5 Apr 2026
Views 66
Rate this term
No ratings yet
🤖 AI Guestbook educational data only
| |
Last 30 days
0 pings T 0 pings W 2 pings T 0 pings F 0 pings S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 6 pings F 2 pings S 3 pings S 1 ping M 0 pings T 0 pings W 0 pings T 0 pings F 1 ping S 0 pings S 0 pings M 0 pings T 0 pings W 0 pings T 0 pings F 0 pings S 1 ping S 1 ping M 0 pings T 0 pings W
No pings yet today
No pings yesterday
Perplexity 9 Amazonbot 9 Scrapy 9 SEMrush 5 Google 4 Ahrefs 4 Meta AI 2 Claude 2 Bing 2 PetalBot 2
crawler 46 crawler_json 2
DEV INTEL Tools & Severity
🔴 Critical ⚙ Fix effort: Medium
⚡ Quick Fix
Use password_hash($pass, PASSWORD_ARGON2ID) to hash, password_verify($input, $hash) to check, session_regenerate_id(true) after successful login, and rate-limit login attempts
📦 Applies To
PHP 7.0+ web cli


✓ schema.org compliant