mansi14883md/AI-Keystroke-Security-System
AI-Based Secure Authentication System Using Keystroke Dynamics
This is a BTech mini project that authenticates a user by typing behavior. It includes a desktop GUI, machine learning model training, multiple user profiles, an admin dashboard, graphs, and a Flask web version for deployment on GitHub and Hugging Face.
Main idea
Instead of checking only the password text, this project also checks how the user types. It uses keystroke dynamics such as hold time, flight time, and engineered typing features to identify genuine users and reject impostors.
Core concepts
Keystroke Dynamics
Keystroke dynamics means identifying a person by typing pattern.
Hold Time
Hold time is the time between pressing and releasing the same key.
Flight Time
Flight time is the time gap between one key and the next key.
Authentication
Authentication means deciding whether the current user is the real authorized user.
Modules
- Keystroke Data Capture
- Dataset Creation
- Machine Learning Model Training
- User Registration and Profile Creation
- User Authentication
- Admin Dashboard
- Accuracy Evaluation
- GUI Login System
- Web Deployment Version
Folder structure
MINOR P/
|-- capture_data.py
|-- train_model.py
|-- register_user.py
|-- authenticate.py
|-- login_gui.py
|-- accuracy_graph.py
|-- backend_utils.py
|-- admin_dashboard.py
|-- profile_compare.py
|-- web_app.py
|-- app.py
|-- Dockerfile
|-- requirements.txt
|-- README.md
|-- .gitignore
|-- data/
| |-- genuine.csv
| |-- impostor.csv
| |-- auth_log.csv
| |-- security_system.db
| `-- user_profiles/
`-- models/
|-- model.pkl
|-- metrics.json
`-- user_profiles/File explanation
capture_data.py
Captures keystroke hold times and stores them in genuine.csv or impostor.csv.
train_model.py
Loads data, creates features, compares models like Random Forest, Extra Trees, and SVM, then saves the best model.
register_user.py
Registers a named user and creates that user's typing profile.
authenticate.py
Runs a simple authentication test outside the main GUI.
login_gui.py
Main desktop application with animations, voice alerts, login logic, and user profile selection.
accuracy_graph.py
Shows model performance graphs and comparison charts.
backend_utils.py
Project backend logic for feature engineering, prediction, SQLite storage, settings, logs, and profile comparison.
admin_dashboard.py
Admin dashboard showing total users, total attempts, granted and denied attempts, export option, and settings.
profile_compare.py
Compares a fresh typing sample with a selected saved user profile.
web_app.py
Flask web app version used for browser deployment.
app.py
Deployment entry point for Hugging Face Spaces.
Local setup
1. Open the project folder
cd "C:\Users\DELL\OneDrive\Desktop\MINOR P"2. Install required libraries
pip install -r requirements.txt3. Capture dataset
python capture_data.pyChoose:
1for genuine samples2for impostor samples
4. Train the model
python train_model.pyThis creates:
models/model.pklmodels/metrics.json
5. Register users
python register_user.py6. Run desktop GUI
python login_gui.py7. Run admin dashboard
python admin_dashboard.py8. Show graphs
python accuracy_graph.py9. Run web version locally
python app.pyThen open:
http://127.0.0.1:7860Expected outputs
Training output
- best model name
- accuracy
- cross-validation results
- saved model and metrics
Desktop GUI output
- animated login screen
- access granted or denied
- voice and alert effects
- live status and confidence
Admin output
- total users
- total login attempts
- granted and denied counts
- exported history
Graph output
- accuracy
- precision
- recall
- F1-score
- model comparison
- user sample counts
Web output
- browser-based login page
- admin page at
/admin
GitHub upload
Step 1
git init
git add .
git commit -m "Initial commit"Step 2
Create a new repository on GitHub, then run:
git branch -M main
git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPOSITORY_NAME.git
git push -u origin mainHugging Face deployment
Tkinter desktop GUI cannot run directly on Hugging Face Spaces. Use the Flask web version instead.
Step 1
Create a new Hugging Face Space and choose:
Docker
Step 2
Upload these important files:
app.pyweb_app.pybackend_utils.pyrequirements.txtDockerfile
Step 3
If you want live authentication to work immediately, also upload:
models/model.pklmodels/metrics.jsonmodels/user_profiles/- any required demo data in
data/
Step 4
Hugging Face will build the Space automatically and run it on port 7860.
Best demo commands
Desktop demo
python train_model.py
python register_user.py
python login_gui.py
python accuracy_graph.pyWeb demo
python app.py1-minute explanation
This project is an AI-based secure authentication system using keystroke dynamics. It checks not only the typed text, but also the user's typing behavior. First, typing samples are collected from genuine and impostor users. Then machine learning models are trained on features like hold time and flight time. Each user can also register a personal typing profile. During login, the current typing pattern is compared with both the trained model and the stored user profile. If the pattern matches, access is granted; otherwise, access is denied. The project also includes an animated desktop GUI, graphs, admin tools, and a web deployment version.
Real-life applications
- Banking login security
- Office system login
- Online examination verification
- Secure lab or research access
- Background user verification in web apps
Viva questions
1. What is keystroke dynamics?
It is a behavioral biometric method that identifies users from typing patterns.
2. What is hold time?
It is the time between key press and key release.
3. Why is machine learning used?
It learns the typing pattern of genuine and impostor users and helps classify new samples.
4. Which models are used?
Random Forest, Extra Trees, and SVM.
5. Why is this project useful?
It improves security beyond normal password-only systems without extra hardware.
