mansi14883md/AI-Keystroke-Security-System
1
1---2title: AI Keystroke Security System3emoji: ๐4colorFrom: blue5colorTo: purple6sdk: docker7pinned: false8---9 10# AI-Based Secure Authentication System Using Keystroke Dynamics11 12This 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.13 14## Main idea15 16Instead 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.17 18## Core concepts19 20### Keystroke Dynamics21Keystroke dynamics means identifying a person by typing pattern.22 23### Hold Time24Hold time is the time between pressing and releasing the same key.25 26### Flight Time27Flight time is the time gap between one key and the next key.28 29### Authentication30Authentication means deciding whether the current user is the real authorized user.31 32## Modules33 341. Keystroke Data Capture352. Dataset Creation363. Machine Learning Model Training374. User Registration and Profile Creation385. User Authentication396. Admin Dashboard407. Accuracy Evaluation418. GUI Login System429. Web Deployment Version43 44## Folder structure45 46```text47MINOR P/48|-- capture_data.py49|-- train_model.py50|-- register_user.py51|-- authenticate.py52|-- login_gui.py53|-- accuracy_graph.py54|-- backend_utils.py55|-- admin_dashboard.py56|-- profile_compare.py57|-- web_app.py58|-- app.py59|-- Dockerfile60|-- requirements.txt61|-- README.md62|-- .gitignore63|-- data/64| |-- genuine.csv65| |-- impostor.csv66| |-- auth_log.csv67| |-- security_system.db68| `-- user_profiles/69`-- models/70 |-- model.pkl71 |-- metrics.json72 `-- user_profiles/73```74 75## File explanation76 77### capture_data.py78Captures keystroke hold times and stores them in `genuine.csv` or `impostor.csv`.79 80### train_model.py81Loads data, creates features, compares models like Random Forest, Extra Trees, and SVM, then saves the best model.82 83### register_user.py84Registers a named user and creates that user's typing profile.85 86### authenticate.py87Runs a simple authentication test outside the main GUI.88 89### login_gui.py90Main desktop application with animations, voice alerts, login logic, and user profile selection.91 92### accuracy_graph.py93Shows model performance graphs and comparison charts.94 95### backend_utils.py96Project backend logic for feature engineering, prediction, SQLite storage, settings, logs, and profile comparison.97 98### admin_dashboard.py99Admin dashboard showing total users, total attempts, granted and denied attempts, export option, and settings.100 101### profile_compare.py102Compares a fresh typing sample with a selected saved user profile.103 104### web_app.py105Flask web app version used for browser deployment.106 107### app.py108Deployment entry point for Hugging Face Spaces.109 110## Local setup111 112### 1. Open the project folder113 114```bash115cd "C:\Users\DELL\OneDrive\Desktop\MINOR P"116```117 118### 2. Install required libraries119 120```bash121pip install -r requirements.txt122```123 124### 3. Capture dataset125 126```bash127python capture_data.py128```129 130Choose:131- `1` for genuine samples132- `2` for impostor samples133 134### 4. Train the model135 136```bash137python train_model.py138```139 140This creates:141- `models/model.pkl`142- `models/metrics.json`143 144### 5. Register users145 146```bash147python register_user.py148```149 150### 6. Run desktop GUI151 152```bash153python login_gui.py154```155 156### 7. Run admin dashboard157 158```bash159python admin_dashboard.py160```161 162### 8. Show graphs163 164```bash165python accuracy_graph.py166```167 168### 9. Run web version locally169 170```bash171python app.py172```173 174Then open:175 176```text177http://127.0.0.1:7860178```179 180## Expected outputs181 182### Training output183- best model name184- accuracy185- cross-validation results186- saved model and metrics187 188### Desktop GUI output189- animated login screen190- access granted or denied191- voice and alert effects192- live status and confidence193 194### Admin output195- total users196- total login attempts197- granted and denied counts198- exported history199 200### Graph output201- accuracy202- precision203- recall204- F1-score205- model comparison206- user sample counts207 208### Web output209- browser-based login page210- admin page at `/admin`211 212## GitHub upload213 214### Step 1215 216```bash217git init218git add .219git commit -m "Initial commit"220```221 222### Step 2223Create a new repository on GitHub, then run:224 225```bash226git branch -M main227git remote add origin https://github.com/YOUR_USERNAME/YOUR_REPOSITORY_NAME.git228git push -u origin main229```230 231## Hugging Face deployment232 233Tkinter desktop GUI cannot run directly on Hugging Face Spaces. Use the Flask web version instead.234 235### Step 1236Create a new Hugging Face Space and choose:237- `Docker`238 239### Step 2240Upload these important files:241- `app.py`242- `web_app.py`243- `backend_utils.py`244- `requirements.txt`245- `Dockerfile`246 247### Step 3248If you want live authentication to work immediately, also upload:249- `models/model.pkl`250- `models/metrics.json`251- `models/user_profiles/`252- any required demo data in `data/`253 254### Step 4255Hugging Face will build the Space automatically and run it on port `7860`.256 257## Best demo commands258 259### Desktop demo260 261```bash262python train_model.py263python register_user.py264python login_gui.py265python accuracy_graph.py266```267 268### Web demo269 270```bash271python app.py272```273 274## 1-minute explanation275 276This 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.277 278## Real-life applications279 2801. Banking login security2812. Office system login2823. Online examination verification2834. Secure lab or research access2845. Background user verification in web apps285 286## Viva questions287 288### 1. What is keystroke dynamics?289It is a behavioral biometric method that identifies users from typing patterns.290 291### 2. What is hold time?292It is the time between key press and key release.293 294### 3. Why is machine learning used?295It learns the typing pattern of genuine and impostor users and helps classify new samples.296 297### 4. Which models are used?298Random Forest, Extra Trees, and SVM.299 300### 5. Why is this project useful?301It improves security beyond normal password-only systems without extra hardware.
302 