A secure, modern authentication system built with PHP and MongoDB, featuring comprehensive security measures including secure password reset functionality, CSRF protection, and reCAPTCHA integration.
- User registration with email verification
- Secure login with brute force protection
- Password reset functionality
- Two-factor authentication (2FA)
- Remember me functionality
- CSRF protection
- Input validation and sanitization
- MongoDB integration for data storage
- Secure session management
- Content security headers
- Responsive UI using Bootstrap
Having trouble getting started? Check out our comprehensive FAQ Guide for solutions to common issues including:
- 🔧 reCAPTCHA Configuration - Fixing domain and localhost issues
- 🔗 Domain & URL Settings - Configuring APP_URL correctly
- 🛡️ Security & .htaccess Rules - Understanding CSP policies
- 🐛 Debugging & Logging - Enabling debug mode and logs
- 📧 Email Configuration - Setting up Gmail SMTP
- 🗄️ Database Issues - MongoDB Atlas connection problems
- 📁 File Permissions - Fixing directory access errors
- ⚡ Performance Optimization - Improving system performance
- 📦 Installation Issues - Prerequisites and setup checklist
- PHP 7.4 or higher
- MongoDB server
- Composer (for managing dependencies)
- Web server with SSL support (recommended for production)
- Google reCAPTCHA API keys
-
Clone the repository to your web server directory:
git clone https://github.com/yourusername/auth-system.git cd auth-system
-
Install dependencies via Composer:
composer install
-
Copy the example environment file and update it with your settings:
cp .env.example .env
Then edit the
.env
file with your specific configuration:# Application settings APP_NAME="Authentication System" APP_URL="http://localhost/auth" APP_DEBUG=true # MongoDB settings MONGODB_URI="mongodb://username:password@localhost:27017" MONGODB_DATABASE="auth" # Email settings SMTP_HOST="smtp.example.com" SMTP_PORT=587 SMTP_USERNAME="your-email@example.com" SMTP_PASSWORD="your-password" SMTP_FROM="noreply@example.com" SMTP_FROM_NAME="Authentication System" # Security settings JWT_SECRET="your-jwt-secret-key" CSRF_TOKEN_EXPIRY=7200 SESSION_LIFETIME=3600 # reCAPTCHA settings RECAPTCHA_SITE_KEY="your-recaptcha-site-key" RECAPTCHA_SECRET_KEY="your-recaptcha-secret-key"
-
Create the required MongoDB collections:
users
password_resets
sessions
failed_logins
-
Ensure proper permissions are set:
For Linux/Unix:
chmod 755 -R /path/to/auth chmod 777 -R /path/to/auth/logs
For Windows, ensure proper folder permissions in XAMPP environments:
# Verify XAMPP has proper file access in Windows # You can adjust permissions through File Explorer > Properties > Security tab
auth/
├── auth-handlers/ # Authentication handlers
│ ├── handlers/ # Request handlers
│ │ ├── contact_handler.php
│ │ └── register_handler.php
│ ├── logs/ # Application logs
│ │ └── email.log, error.log, etc.
│ ├── setup/ # Setup utilities
│ │ └── install_phpmailer.php
│ └── utils/ # Utility functions
│ ├── csrf_protection.php
│ ├── email.php
│ ├── mongodb_helper.php
│ ├── rate_limiter.php
│ ├── recaptcha.php
│ ├── session_manager.php
│ └── validation.php
├── config/ # Configuration files
│ ├── config.php # Main configuration
│ ├── database.php # Database configuration
│ ├── env_loader.php # Environment variable loader
│ └── mongodb_setup.php # MongoDB setup
├── dashboard/ # User dashboard
│ ├── dashboard.php # Main dashboard page
│ └── logout.php # Logout functionality
├── logs/ # Log files
│ ├── password_reset.log
│ └── mail/
├── pages/ # Public-facing pages
│ ├── contact.php
│ ├── forgot-password.php
│ ├── login.php
│ ├── register.php
│ ├── registration-success.php
│ ├── reset-password.php
│ └── verify.php
├── vendor/ # Composer dependencies
├── .env # Environment variables
├── .env.example # Example environment configuration
├── .htaccess # Apache web server configuration
└── index.html # Landing page
- Password Storage: All passwords are hashed using PHP's
password_hash()
with bcrypt - CSRF Protection: All forms include CSRF tokens to prevent cross-site request forgery
- Brute Force Protection: Automatic account lockout after multiple failed login attempts
- Content Security Headers: Implements strict security headers for XSS protection
- Secure Session Management: Sessions are protected against hijacking and fixation attacks
- Input Validation: All user inputs are validated and sanitized
- reCAPTCHA: Integration with Google reCAPTCHA to prevent automated attacks
- Rate Limiting: API requests are rate-limited to prevent abuse
- Secure Password Reset: One-time tokens with expiration for password reset functionality
- Logging: Comprehensive logging of authentication events and security incidents
Users can create an account by providing:
- Email address
- Password (with strength requirements)
- Basic profile information
A verification email is sent to confirm the email address before the account is activated.
Users can log in using:
- Email address
- Password
- Remember me option for extended session
- User requests a password reset by entering their email
- A secure token is generated and sent via email
- User clicks the link and sets a new password
- Old sessions are invalidated for security
- Navigate to profile settings to enable 2FA
- Scan the provided QR code with an authenticator app
- Enter the verification code to confirm setup
- 2FA will be required for future logins
To run the project in development mode:
-
Set
APP_DEBUG=true
in your.env
file -
Enable PHP error reporting in your
php.ini
-
Use the built-in PHP server for testing:
php -S localhost:8000
💡 Troubleshooting: If you encounter any issues during development, check the FAQ Guide for common solutions.
For production environments:
- Set
APP_DEBUG=false
in your.env
file - Use a proper web server (Apache, Nginx) with SSL
- Secure the
.env
file from public access - Set up proper firewall and network security
- Configure regular database backups
- Enable HTTPS and HSTS for secure connections
- Consider implementing rate limiting at the server level
This project is licensed under the MIT License - see the LICENSE file for details.
Contributions are welcome! Please feel free to submit a Pull Request.
- Fork the repository
- Create your feature branch (
git checkout -b feature/amazing-feature
) - Commit your changes (
git commit -m 'Add some amazing feature'
) - Push to the branch (
git push origin feature/amazing-feature
) - Open a Pull Request