Deep dive into the purpose and behavior of each component in the PHP Authentication Template.
password_hash()
, password_verify()
random_bytes()
, random_int()
hash_equals()
(timing‑safe compares)Apache rewrite rules convert human‑friendly paths into physical script executions. This produces framework‑like cleanliness without imposing a full MVC stack.
/login → pages/login.php
/register → pages/register.php
/admin-dashboard → pages/admin.php
/2fa-setup → pages/2fa-setup.php
/2fa-verify → pages/2fa-verify.php
/request-another-email → pages/email.php
Static assets (CSS/JS) are served directly; nonexistent paths route to 404.php
.
pending_2fa_user_id
state.user_id
or admin_id
).Adds friction before sensitive operation (enabling 2FA) to mitigate session‑cookie theft scenarios.
user_2fa_reauth_passed
and redirects to enrollment.twofa_secret
for admin.force2fa_email_passed
.File | Purpose | Key Actions |
---|---|---|
index.php | Landing + newsletter | reCAPTCHA, rate limit, insert subscriber |
pages/register.php | Account creation | Hash password, issue verify token |
pages/email.php | Resend verification | Throttle, new token, email send |
pages/verify.php | Consume token | Expire or activate user |
pages/login.php | Primary auth | reCAPTCHA, pending 2FA logic |
pages/2fa-verify.php | TOTP check | Promote session to full |
pages/2fa-setup.php | TOTP enrollment | QR provisioning, store secret, logout |
pages/dashboard.php | User portal | Password re-auth modal |
pages/admin.php | Admin panel | Forced 2FA, messaging, newsletter |
pages/reset.php | Request password reset | Create reset token + email |
pages/password.php | Reset consume | Validate token & update hash |
contact.php | Public form | Store message, send confirmation |
TOTP secrets generated via OTPHP, encoded into provisioning URI for scanning. Client authenticator apps (Google / Microsoft / Authy) produce rolling codes. The server only stores the shared secret (no recovery codes yet — recommended addition).
PHPMailer Choice: Mature, SMTP capable, robust error handling, easier debug than bare `mail()`.
You can later migrate to a full MVC or SPA architecture once business needs outgrow the template.