A robust Biometric Authentication System that verifies identity based on typing patterns (rhythm, flight time, dwell time) using a bi-directional LSTM neural network.
The model uses a dual-branch architecture to capture both the timing and the sequence of keystrokes.
graph TD
A["Input: Time Features"] --> B["Masking Layer"]
B --> C["Bi-LSTM (32 Units)"]
C --> D["Dropout (0.4)"]
E["Input: Key IDs"] --> F["Embedding (32 Dim)"]
F --> G["LSTM (32 Units)"]
G --> H["Dropout (0.4)"]
D --> I[Concatenate]
H --> I
I --> J["Dense (32 Unit) + ReLU"]
J --> K["Output (Softmax)"]
Clone the repo and install dependencies:
git clone https://github.com/colak-inanc/keystroke-dynamic-dev.git
cd neural-network
pip install -r requirements.txtStart the FastAPI server:
cd web-app
uvicorn v3-copy:app --reload --host 0.0.0.0 --port 8000The application will automatically train the model in the background as new users register.
neural-network/
├── 📁 web-app/
│ ├── 📁 app/
│ │ ├── routes.py # API Endpoints (Login, Register)
│ │ ├── services.py # Feature Extraction & Model Loading
│ │ ├── training.py # Robust Training Pipeline (Bi-LSTM)
│ │ └── imposter_generator.py# Synthetic Data Generation
│ ├── 📁 keystroke_data/ # User Data Storage (JSON)
│ ├── 📁 static/ # CSS & JS Assets
│ ├── 📁 templates/ # HTML Templates
│ ├── manual_trigger.py # Script to force model retraining
│ ├── model_test.py # Model Evaluation Suite
│ └── v3-copy.py # Main Application Entry Point
├── 📁 model/
│ └── keystroke_lstm_model.keras # Trained Model Artifact
├── .gitignore
├── requirements.txt
└── ReadMe.md
- User Analytics Hub: Provides a comprehensive overview of the user's biometric performance.
- Real-time Stats: key metrics like Total Sessions, Average Accuracy, Typing Speed (WPM), and Overall Success Rate.
- Session History: Detailed log of recent authentication attempts with status indicators (Success/Fail) and downloadable CSV reports.
- Multi-Step Data Collection: Implements a robust 3-step enrollment process to capture consistent behavioral data patterns.
- Live Feedback System: Calculates and displays real-time WPM (Words Per Minute), Accuracy, and Duration to guide the user.
- Deep Capture: Records precise timestamp data for
keydownandkeyupevents, including dwell time and flight time calculations.
- Biometric Challenge: Presents users with a dynamic text challenge to verify their identity based on typing rhythm, not just credentials.
- Real-time Validation: Captures keystrokes on-the-fly and sends them to the LSTM model for immediate inference.
- Security: Seamlessly integrates with the backend to establish secure
HttpOnlysessions upon successful biometric verification.
After successfully logging in, the system will redirect you to a dashboard page.
The system collects high-precision raw keystroke data and transforms it into complex behavioral features for the AI model.
Each session records a sequence of keystroke events with precise timestamps.
- Key: The character pressed (e.g., "a", "Shift", "Backspace").
- Event Type:
keydownorkeyup. - Timestamp: High-resolution time (ms) from the client performance API.
{
"key": "a",
"event_type": "keydown",
"timestamp": 1702503546123.45,
"code": "KeyA"
}The system extracts a rich set of features from the raw keystroke data to train the AI model.
features = {
"key": "a",
"event_type": "keydown",
"timestamp": 1702503546123.45,
"code": "KeyA",
"dwell_time": 0.1,
"flight_time": 0.2,
"wpm": 50,
"accuracy": 95,
"duration": 10
}| Feature Category | Description | Metric |
|---|---|---|
| Temporal | Timing patterns intrinsic to the user. | Dwell Time: Duration a key is pressed. Flight Time: Time interval between releasing a key and pressing the next. Down-Down Latency: Time between two consecutive key presses. |
| N-Graph | Rhythm patterns across key combinations. | Digraphs (2-keys): Latency for specific pairs (e.g., 't' -> 'h'). Trigrams (3-keys): Flow speed across common triplets (e.g., 't-h-e'). |
| Mechanics | How the user interacts with the keyboard. | WPM: Words Per Minute. Error Rate: Frequency of backspace usage. Shift Usage: Preference for Left vs. Right Shift. |
| Statistical | Overall session consistency. | Rhythm Consistency: Variance in typing speed. Speed Changes: Acceleration/Deceleration patterns. |
The collected raw keyboard event data is converted into temporal features during data preprocessing steps performed before model training and saved in .csv format on a user-by-user basis. The resulting feature files are used for training deep learning models.
Session-based grouping is enforced during train/validation split to prevent sliding-window leakage across sessions.
| Command | Description |
|---|---|
python manual_trigger.py |
Forces a complete model retraining using all available data. |
python model_test.py |
Runs the evaluation suite. Generates Confusion Matrix and AUC Report. |
- 1:1 Imposter Generation: Training enforces a 50/50 split between Real Users and Synthetic Imposters to prevent model collapse.
- HttpOnly Cookies: Secure session management.
- Early Stopping: Prevents overfitting to small datasets.


