A simple and secure login/registration module built with Flask, Socket.IO, and MySQL/MariaDB.
- User registration with validation
- Secure password hashing using bcrypt
- User login with rate limiting (3 failed attempts = 5 minute lockout)
- Real-time communication using Socket.IO
- MySQL/MariaDB database integration
pip install -r requirements.txtCreate database and user in MySQL/MariaDB:
CREATE DATABASE login_module_db;
CREATE USER 'login_user'@'localhost' IDENTIFIED BY 'your_secure_password';
GRANT ALL PRIVILEGES ON login_module_db.* TO 'login_user'@'localhost';
FLUSH PRIVILEGES;Run the setup script:
mysql -u login_user -p login_module_db < setup_database.sqlEdit backend.py and update:
DB_CONFIG = {
'user': 'login_user',
'password': 'your_secure_password',
'host': 'localhost',
'port': 3306,
'database': 'login_module_db'
}
app.config['SECRET_KEY'] = 'your-secure-random-key-here'python backend.pyOpen browser: http://localhost:4000
backend.py- Main Flask applicationstatic/script.js- Frontend JavaScriptstatic/style.css- Stylingtemplates/index.html- HTML templatesetup_database.sql- Database schemarequirements.txt- Python dependencies
- Register: Click "Register" tab, enter username (3+ chars) and password (6+ chars)
- Login: Click "Login" tab, enter credentials
- Password hashing with bcrypt
- Rate limiting (3 failed attempts = 5 min lockout)
- Session management
- SQL injection protection
- Input validation
- Change port: Modify
portinsocketio.run() - Adjust rate limiting: Modify timeout in
cleanup_login_attempts() - Customize UI: Edit
static/style.cssandtemplates/index.html