Skip to content

alricium/php-authentication

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

4 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

๐Ÿ” PHPAuth โ€” High-Security PHP Authentication System

PHP MySQL PHPMailer License

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


โœจ Features

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 โœ…

๐Ÿ›๏ธ Architecture

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

โš™๏ธ Setup

Prerequisites

  • PHP 8.2+
  • MySQL 5.7+
  • Apache with mod_rewrite enabled (XAMPP recommended)
  • Composer
  • A Gmail account with an App Password

1. Clone the Repository

git clone https://github.com/alricium/php-authentication.git
cd php-authentication

2. Install Dependencies

composer install

3. Create the Database

Open 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
);

4. Configure Environment Variables

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:

  1. Go to Google Account โ†’ Security
  2. Enable 2-Step Verification
  3. Go to App Passwords and create one
  4. Copy the 16-character password into MAIL_PASS

5. Configure Apache (XAMPP)

Make sure mod_rewrite is enabled in your httpd.conf:

LoadModule rewrite_module modules/mod_rewrite.so

And ensure AllowOverride All is set in httpd-vhosts.conf or the main config for the htdocs directory.

6. Access the App

Open your browser and navigate to:

http://localhost/phpauth/

๐Ÿš€ Usage

Registration Flow

  1. Go to /register
  2. Fill in username, email, and password
  3. Check your email for a verification link
  4. Click the link to activate your account
  5. You're in! ๐ŸŽ‰

Login

  • 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

Password Reset

  1. Go to /forgot-password
  2. Enter your account email
  3. Click the reset link sent to your inbox
  4. Set a new strong password

๐Ÿ›ก๏ธ Security

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

๐ŸŽจ UI Design

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

๐Ÿ”— Routes

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

๐Ÿ“ฆ Dependencies

Package Version Purpose
PHPMailer ^7.0 SMTP email delivery

๐Ÿง‘โ€๐Ÿ’ป Contributing

Pull requests are welcome! For major changes, please open an issue first to discuss what you'd like to change.

  1. Fork the repository
  2. Create your feature branch (git checkout -b feature/AmazingFeature)
  3. Commit your changes (git commit -m 'Add some AmazingFeature')
  4. Push to the branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

๐Ÿ“„ License

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!

About

๐Ÿ” Secure Vanilla PHP Authentication System featuring JWT-like Refresh Token logic, PDO (SQL Injection protection), Password Hashing (BCrypt), and .env configuration. Built with a focus on security and modern PHP best practices.

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors

Languages