A simple PHP, MySQL, and JavaScript-based registration and login system with modern UI, password strength meter, and captcha.
- User registration with email, password, and captcha
- Password strength indicator
- User login with session management
- Dashboard with personalized greeting
- Logout functionality
- Responsive and modern UI (CSS/FontAwesome)
- Environment-based configuration
- PHP 7.4+ (with PDO extension)
- MySQL 8+ (Docker or local)
- Nginx or Apache web server
- Docker (optional, for MySQL)
git clone https://github.com/tilakpoudel/login-system
cd login-systemCopy the example .env file and edit as needed:
cp .env.example .envEdit .env to match your MySQL setup (especially if using Docker):
DB_HOST=127.0.0.1
DB_PORT=3306
DB_NAME=database_name
DB_USER=db_user_name
DB_PASSWORD=db_password
If you want to use Docker for MySQL, add this to your docker-compose.yml:
version: '3'
services:
mysql84:
container_name: mysql-db84
image: mysql:8.4
env_file:
- .env
ports:
- "3306:3306"
networks:
- local_default
networks:
local_default:
driver: bridgeThen run:
docker-compose up -dConnect to MySQL and run:
CREATE DATABASE IF NOT EXISTS database_name;
USE database_name;
CREATE TABLE IF NOT EXISTS users (
id INT AUTO_INCREMENT PRIMARY KEY,
first_name VARCHAR(100),
last_name VARCHAR(100),
email VARCHAR(255) UNIQUE,
password VARCHAR(255)
);server {
listen 80;
server_name localhost;
root /var/www/assignment;
index index.php index.html;
location / {
try_files $uri $uri/ /index.php?$query_string;
}
location ~* \.(css|js|png|jpg|jpeg|gif|ico)$ {
try_files $uri =404;
expires 1d;
add_header Cache-Control "public";
}
location ~ \.php$ {
include snippets/fastcgi-php.conf;
fastcgi_pass unix:/run/php/php8.3-fpm.sock; # Adjust PHP version if needed
fastcgi_param SCRIPT_FILENAME $document_root$fastcgi_script_name;
include fastcgi_params;
}
location ~ /\.ht {
deny all;
}
}Place the project in /var/www/assignment and ensure mod_rewrite is enabled.
- Visit http://localhost/assignment/ in your browser.
- Register a new account.
- Login with your credentials.
- On successful login, you'll be redirected to the dashboard.
- Use the logout link to end your session.
assignment/
├── index.php
├── dashboard.php
├── login.php
├── register.php
├── logout.php
├── db.php
├── style.css
├── script.js
├── .env
└── .env.example
- Never commit your real
.envfile to public repositories. - Use HTTPS in production.
- Passwords are hashed using PHP's
password_hash. - Captcha is implemented in JS for demo purposes; for production, use a server-side or third-party solution.
MIT