A secure authentication system built using Flask and MySQL, implementing essential security controls such as password hashing, brute-force attack protection, and account lockout mechanisms.
- User Registration & Login
- Secure password hashing (Werkzeug)
- Brute-force attack protection
- Temporary account lock after failed attempts
- Session-based authentication
- Flash messaging for user feedback
- Clean and simple database schema
- Backend: Python (Flask)
- Database: MySQL
- Security: Werkzeug password hashing
- Frontend: HTML,CSS
- Database Name:
secure_logins - Table Name:
users
-- =============================================
-- Secure Login System Database Schema
-- Database: secure_logins
-- =============================================
CREATE DATABASE IF NOT EXISTS secure_logins;
USE secure_logins;
CREATE TABLE users (
id INT AUTO_INCREMENT PRIMARY KEY,
username VARCHAR(50) NOT NULL UNIQUE,
email VARCHAR(100) NOT NULL UNIQUE,
password VARCHAR(255) NOT NULL, -- hashed password only
created_at TIMESTAMP DEFAULT CURRENT_TIMESTAMP,
failed_attempts INT DEFAULT 0,
lock_until DATETIME DEFAULT NULL
);- Passwords are hashed using
generate_password_hash() - Password verification uses
check_password_hash() - Plaintext passwords are never stored
- Maximum login attempts: 3
- Account lock duration: 15 minutes
- Failed attempts tracked per user
- Account is temporarily locked after consecutive failures
- Login blocked until
lock_untilexpires
secure_login/
│
├── app.py
├── templates/
│ ├── login.html
│ ├── register.html
│ └── home.html
├── static/
│ └── styles.css
├── README.md
└── requirements.txtgit clone https://github.com/Ak786s/secure_login.git
cd secure_loginpip install flask mysql-connector-python werkzeugUpdate database credentials in app.py:
db = mysql.connector.connect(
host="hostname",
user="username",
password="password",
database="secure_logins"
)python app.pyAccess the app at:
http://127.0.0.1:5000/
-- Fetch user for login
SELECT * FROM users WHERE email = ?;
-- Insert new user
INSERT INTO users (username, email, password) VALUES (?, ?, ?);
-- Update failed attempts
UPDATE users SET failed_attempts = failed_attempts + 1 WHERE email = ?;
-- Lock user account
UPDATE users SET lock_until = ? WHERE email = ?;
-- Reset attempts after successful login
UPDATE users SET failed_attempts = 0, lock_until = NULL WHERE email = ?;- Always use prepared statements (implemented)
- Do not hardcode secret keys in production
- Disable
debug=Truein production - Use HTTPS in real deployments
- Role-based access control (RBAC)
- Password reset via email
- Login audit logs
- CAPTCHA integration
- Multi-Factor Authentication (MFA)
Amir Mulla Cybersecurity Enthusiast