Skip to content

foxbyte9/PHPAuthSystem

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

PHP Authentication System

A secure PHP authentication system with user registration, login, and password management features.

Features

  • ✅ User Registration with email validation
  • ✅ Secure Login with password hashing
  • ✅ Password Change functionality
  • ✅ Session Management
  • ✅ Responsive Bootstrap UI
  • ✅ MySQL Database Integration
  • ✅ Input Validation and Security

Requirements

  • PHP 7.4 or higher
  • MySQL 5.7 or higher
  • Web server (Apache/Nginx)

Installation

  1. Clone or download the project files to your web server directory

  2. Create the database:

    -- Run the SQL file in your MySQL database
    source database/schema.sql
  3. Configure database connection: Edit config/database.php and update the database credentials:

    define('DB_HOST', 'localhost');
    define('DB_USER', 'your_username');
    define('DB_PASS', 'your_password');
    define('DB_NAME', 'auth_system');
  4. Set proper file permissions:

    chmod 755 /path/to/PHPAuthSystem
    chmod 644 /path/to/PHPAuthSystem/config/database.php
  5. Access the application: Open your web browser and navigate to your domain/path

Usage

Registration

  • Visit /auth/register.php
  • Fill in username, email, and password
  • System validates email format and password strength
  • Passwords are automatically hashed using password_hash()

Login

  • Visit /auth/login.php
  • Enter username/email and password
  • System verifies credentials and creates session
  • Redirects to dashboard on successful login

Change Password

  • Login and visit /auth/change_password.php
  • Enter current password and new password
  • System verifies current password before updating

Logout

  • Click logout link or visit /auth/logout.php
  • Destroys session and redirects to login

Security Features

  • Password Hashing: Uses PHP's password_hash() with default algorithm
  • Input Validation: Server-side validation for all inputs
  • SQL Injection Prevention: Uses PDO prepared statements
  • Session Security: Proper session management and destruction
  • Email Validation: Built-in email format validation
  • XSS Protection: HTML special characters are escaped

File Structure

PHPAuthSystem/
├── assets/
│   └── css/
│       └── style.css          # Custom styles
├── auth/
│   ├── login.php              # Login page
│   ├── register.php           # Registration page
│   ├── logout.php             # Logout handler
│   └── change_password.php    # Password change page
├── classes/
│   └── User.php               # User class with all methods
├── config/
│   └── database.php           # Database configuration
├── database/
│   └── schema.sql             # Database schema
├── index.php                  # Home page
├── dashboard.php              # User dashboard
└── README.md                  # This file

Database Schema

The system uses a single users table:

CREATE TABLE users (
    id INT AUTO_INCREMENT PRIMARY KEY,
    username VARCHAR(50) UNIQUE NOT NULL,
    email VARCHAR(100) UNIQUE NOT NULL,
    password VARCHAR(255) NOT NULL,
    created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
    updated_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP
);

Customization

Styling

  • Edit assets/css/style.css to customize the appearance
  • The system uses Bootstrap 5 for responsive design

Database

  • Modify config/database.php for different database settings
  • Update database/schema.sql if you need additional fields

Security

  • Consider adding CSRF protection for forms
  • Implement rate limiting for login attempts
  • Add email verification for registration

Troubleshooting

Common Issues

  1. Database Connection Error

    • Check database credentials in config/database.php
    • Ensure MySQL service is running
    • Verify database exists
  2. Session Issues

    • Check PHP session configuration
    • Ensure proper file permissions
    • Clear browser cookies
  3. Password Hash Issues

    • Ensure PHP version supports password_hash()
    • Check if password_verify() is working correctly

License

This project is open source and available under the MIT License.

Support

For support or questions, please check the code comments or create an issue in the project repository.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published