A production-ready, senior-level PHP authentication system featuring a modern MVC architecture, enterprise-grade security, and a stunning Glassmorphism UI.
Features ยท Architecture ยท Setup ยท Usage ยท Security
| Feature | Status |
|---|---|
| ๐ User Registration | โ |
| ๐ Secure Login (with Remember Me) | โ |
| ๐ง Email Verification | โ |
| ๐ Password Reset via Email | โ |
| ๐ก๏ธ CSRF Protection | โ |
| โฑ๏ธ Rate Limiting & Account Lockout | โ |
| ๐ช Persistent Sessions (Refresh Tokens) | โ |
| ๐จ Premium Glassmorphism Dark UI | โ |
| ๐ฑ Fully Responsive Design | โ |
| ๐ฎ Gmail SMTP (PHPMailer) | โ |
| ๐๏ธ MVC Front Controller Pattern | โ |
PHPAuth is built with a clean MVC architecture and a Front Controller pattern, designed with scalability and maintainability in mind.
phpauth/
โโโ .env # Environment variables (DB, Mail)
โโโ .htaccess # Root redirect โ /public
โโโ .sql # Database schema
โโโ composer.json # Composer dependencies
โ
โโโ config/
โ โโโ db.php # PDO connection + .env loader
โ
โโโ public/ # ๐ Only publicly accessible directory
โ โโโ .htaccess # Clean URL routing
โ โโโ index.php # Front Controller (entry point)
โ โโโ assets/ # CSS, JS, images
โ
โโโ src/ # Core application logic
โ โโโ autoload.php # PSR-4 class autoloader
โ โ
โ โโโ Auth/
โ โ โโโ Auth.php # Core authentication logic
โ โ
โ โโโ Controllers/
โ โ โโโ BaseController.php # Abstract base controller
โ โ โโโ AuthController.php # Login, Register, Reset, Verify
โ โ โโโ ProfileController.php # Dashboard, Settings
โ โ
โ โโโ Helpers/
โ โ โโโ Router.php # Lightweight URL router
โ โ โโโ Security.php # CSRF, sanitization, validation
โ โ
โ โโโ Mail/
โ โโโ Mailer.php # PHPMailer SMTP wrapper
โ
โโโ views/ # Presentation layer
โโโ layout.php # Master layout template
โโโ includes/
โ โโโ header.php # Navigation header
โ โโโ footer.php # Footer
โโโ auth/
โ โโโ login.php
โ โโโ register.php
โ โโโ forgot_password.php
โ โโโ reset_password.php
โ โโโ verify.php
โโโ profile/
โโโ dashboard.php
โโโ settings.php
- PHP 8.2+
- MySQL 5.7+
- Apache with
mod_rewriteenabled (XAMPP recommended) - Composer
- A Gmail account with an App Password
git clone https://github.com/alricium/php-authentication.git
cd php-authenticationcomposer installOpen your MySQL client (e.g., phpMyAdmin) and run the schema in .sql:
CREATE DATABASE phpauth;
USE phpauth;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) UNIQUE NOT NULL,
email VARCHAR(100) UNIQUE NOT NULL,
password_hash VARCHAR(255) NOT NULL,
is_verified TINYINT(1) DEFAULT 0,
verification_token VARCHAR(64),
reset_token VARCHAR(64),
reset_token_expires_at DATETIME,
remember_token VARCHAR(64),
login_attempts INT DEFAULT 0,
lock_until DATETIME,
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP
);Copy and rename the .env file and fill in your details:
# Database
DB_HOST=localhost
DB_NAME=phpauth
DB_USER=root
DB_PASS=your_password
# Gmail SMTP
MAIL_HOST=smtp.gmail.com
MAIL_PORT=587
MAIL_USER=your-email@gmail.com
MAIL_PASS=your-app-password # Gmail App Password (not your normal password)
MAIL_FROM=your-email@gmail.com
MAIL_FROM_NAME="PHPAuth System"How to get a Gmail App Password:
- Go to Google Account โ Security
- Enable 2-Step Verification
- Go to App Passwords and create one
- Copy the 16-character password into
MAIL_PASS
Make sure mod_rewrite is enabled in your httpd.conf:
LoadModule rewrite_module modules/mod_rewrite.soAnd ensure AllowOverride All is set in httpd-vhosts.conf or the main config for the htdocs directory.
Open your browser and navigate to:
http://localhost/phpauth/
- Go to
/register - Fill in username, email, and password
- Check your email for a verification link
- Click the link to activate your account
- You're in! ๐
- Supports login with username or email
- Optional "Remember me" โ keeps you logged in for 30 days using a secure refresh token
- After 5 failed attempts, the account is locked for 5 minutes
- Go to
/forgot-password - Enter your account email
- Click the reset link sent to your inbox
- Set a new strong password
PHPAuth is built with security at its core, following OWASP best practices.
| Protection | Implementation |
|---|---|
| Password Storage | bcrypt hashing via password_hash() |
| CSRF Attacks | Cryptographically secure token per session |
| SQL Injection | PDO prepared statements everywhere |
| XSS | htmlspecialchars() on all output |
| Brute Force | 5-attempt lockout with time-based unlock |
| Session Hijacking | Session regeneration on login |
| Sensitive Files | .env is never publicly accessible |
| Email Tokens | bin2hex(random_bytes(32)) โ cryptographically secure |
| Remember Me | Token stored as hash in DB; rotated on each use |
The frontend is built with a premium Glassmorphism dark-mode aesthetic:
- ๐ Dark-mode first design
- โจ Glassmorphism cards with blur and transparency
- ๐ฏ Tailwind CSS v3 for utility-first styling
- โ๏ธ Google Fonts (Inter + Outfit) for modern typography
- ๐๏ธ Smooth micro-animations on interactive elements
- ๐ Fully responsive for mobile, tablet, and desktop
| Method | Path | Action |
|---|---|---|
GET |
/ |
Dashboard (auth required) |
GET |
/login |
Login page |
POST |
/login |
Process login |
GET |
/register |
Registration page |
POST |
/register |
Process registration |
GET |
/logout |
Logout & destroy session |
GET |
/verify?token=... |
Verify email token |
GET |
/forgot-password |
Forgot password page |
POST |
/forgot-password |
Send reset link |
GET |
/reset-password?token=... |
Reset password page |
POST |
/reset-password |
Process password reset |
GET |
/profile/settings |
Account settings |
POST |
/profile/settings |
Update password |
| Package | Version | Purpose |
|---|---|---|
| PHPMailer | ^7.0 | SMTP email delivery |
Pull requests are welcome! For major changes, please open an issue first to discuss what you'd like to change.
- Fork the repository
- Create your feature branch (
git checkout -b feature/AmazingFeature) - Commit your changes (
git commit -m 'Add some AmazingFeature') - Push to the branch (
git push origin feature/AmazingFeature) - Open a Pull Request
This project is licensed under the MIT License โ see the LICENSE file for details.
Built with โค๏ธ by a Senior PHP Developer
โญ Star this repo if you found it helpful!