A comprehensive PHP user authentication system updated for PHP 8.4+ compatibility with modern security practices.
- User Registration & Login - Complete user management system
- Email Verification - Account activation via email
- Password Reset - Secure password recovery system
- Session Management - Configurable session timeout and multiple sessions
- Cookie Support - "Remember me" functionality
- User Levels - Role-based access control (Admin, Moderator, User, Guest)
- Admin Panel - User management interface
- Modern Security - Uses
password_hash()andpassword_verify()functions - PHP 8.4+ Compatible - Updated for latest PHP versions
- PHP 8.4+
- MySQL 5.7+ or MariaDB 10.3+
- Web Server (Apache, Nginx, or PHP built-in)
- Clone or download the repository
- Configure database settings in
lib/config.php - Create database and import the required tables
- Update site settings in
lib/config.php - Start development server:
php -S localhost:8000 - Access application at
http://localhost:8000
Create a MySQL database and update the credentials in lib/config.php:
define("DB_HOST","localhost");
define("DB_NAME","your_database_name");
define("DB_USER","your_username");
define("DB_PASS","your_password");Update the site settings in lib/config.php:
define("SITE_NAME", "Your Site Name");
define("SITE_PATH","https://yoursite.com/");
define("ADMIN_EMAIL", "admin@yoursite.com");For SMTP email functionality, configure the email settings:
define("USE_SMTP", TRUE);
define("SMTP_HOST", "smtp.gmail.com");
define("SMTP_PORT", "587");
define("SMTP_USER", "your-email@gmail.com");
define("SMTP_PASS", "your-password");
define("USE_SSL", TRUE);<?php
require_once('lib/userauth.class.php');
// Check if user is logged in as USER, MOD, or ADMIN
$user->is("USER,MOD,ADMIN");
// Get user property
$username = $user->getProperty('user');
$email = $user->getProperty('email');
?>$data = array(
'user' => $username,
'pass' => $password,
'email' => $email,
'name' => $fullname
);
$user->insertUser($data);$user->login($username, $password, $remember_me);phpUserAuth/
├── lib/ # Core library files
│ ├── config.php # Configuration settings
│ ├── userauth.class.php # Main authentication class
│ ├── validation.class.php # Input validation
│ ├── form.class.php # Form handling
│ ├── mailer.class.php # Email functionality
│ └── util.class.php # Utility functions
├── admin/ # Admin panel
│ ├── index.php # Admin dashboard
│ └── action.php # Admin actions
├── templates/ # Email templates
│ ├── verification.html # Account verification
│ ├── password.html # Password reset
│ └── username.html # Username recovery
├── inc/ # Assets (CSS, JS)
├── index.php # Main page
├── login.php # Login page
├── signup.php # Registration page
├── account.php # User account page
├── forgot.php # Password recovery
├── verify.php # Account verification
├── resetpass.php # Password reset
└── composer.json # Dependencies
- Modern Password Hashing: Uses PHP's
password_hash()withPASSWORD_DEFAULT - Backward Compatibility: Supports legacy SHA1 hashes during migration
- SQL Injection Prevention: All queries use prepared statements and escaping
- Session Security: Configurable timeouts and session validation
- CSRF Protection: Form validation and secure redirects
- Input Sanitization: Comprehensive input filtering
define("GUEST", 0); // Not logged in
define("ADMIN", 1); // Administrator
define("MOD", 2); // Moderator
define("USER", 3); // Regular userdefine("MULTIPLE_SESSIONS", TRUE); // Allow multiple sessions
define("SESSION_TIMEOUT", 60*30); // 30 minutes timeout
define("REMEMBER_USER", TRUE); // Enable "Remember Me"
define("COOKIE_EXPIRES", 60*60*24); // 1 day cookie expirydefine("SEND_ACTIVATION_MAIL", TRUE); // Send activation email
define("AUTO_ACTIVATE", FALSE); // Auto-activate accountsThe system automatically handles migration from older SHA1-based passwords. When users with legacy passwords log in, their passwords are automatically upgraded to the new secure format.
- Fork the repository
- Create a feature branch
- Make your changes
- Ensure PHP 8.4+ compatibility
- Submit a pull request
This project is open source. Please check the individual files for specific licensing information.
For issues and questions:
- Check the documentation in
CLAUDE.md - Review the configuration in
lib/config.php - Enable development mode for detailed error messages
- Check PHP error logs for debugging
- Updated for PHP 8.4+ compatibility
- Replaced SHA1 password hashing with
password_hash() - Removed deprecated
get_magic_quotes_gpc()usage - Fixed string access syntax (curly braces → square brackets)
- Added proper error reporting for modern PHP
- Added Composer support
- Improved security practices