A clean, modern PHP user authentication system built using Object-Oriented Programming (OOP). Designed as a reusable base for any PHP-based website requiring user management, roles, and admin tools.
- User Registration
- User Login
- Secure Logout
- Password Hashing with
password_hash() - Session-based Authentication
- Password Reset via Email (Forgot Password)
- CSRF Token Protection on all forms
- One-time success/error messages
- Displays messages after login, logout, password reset, etc.
- Flash helper class included
- Logged-in users can update their:
- Username
- Password (optional)
- Input validation and secure update logic
- Forgot Password request form
- Secure reset token generation and expiry handling
- Password reset link via email
- Reset form with confirmation
- Flash success message on reset
- Token-based CSRF defense on all user input forms
- Session-bound random token generation and validation
- Role support:
user,admin - Admin-only dashboard access
- Role checked through session and Auth class
- View all users (ID, Username, Email, Role)
- Pagination for user listing
- Filter/search users by role, email, or username
- Edit user info and role
- Delete users (except self)
- Role-specific navigation
header.phpandfooter.phpshared across all pages- Flash message and navbar logic in header
- Bootstrap 5 CDN for styling
/app ├── /controllers # Auth class, Role manager ├── /models # User model ├── /helpers # Flash messaging, CSRF helpers
/config # Database config (PDO)
/includes # Header and footer includes
/public # Web-accessible files (login, register, dashboard, admin)
/README.md
- PHP 8.2 or higher
- MySQL 5.7+/MariaDB 10+
- Web server (Apache/Nginx) with rewrite enabled
- Clone or download this repository.
- Set up a database and import the
database.sqlfile (or use provided schema). - Update
/config/database.phpwith your database credentials. - Start your local server or deploy to a PHP-supported host.
I have tested all of the code - everything is working as intended. If you come across any bugs please open an issue. I will continue to update this system with more features, etc. I hope everyone enjoys using it for projects.
MIT License — free to use and modify for personal or commercial projects.