Skip to content

colak-inanc/keystroke-dynamic-dev

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

22 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

A robust Biometric Authentication System that verifies identity based on typing patterns (rhythm, flight time, dwell time) using a bi-directional LSTM neural network.


🏗️ Architecture

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)"]
Loading

🚀 Quick Start

1. Installation

Clone the repo and install dependencies:

git clone https://github.com/colak-inanc/keystroke-dynamic-dev.git
cd neural-network
pip install -r requirements.txt

2. Run Application

Start the FastAPI server:

cd web-app
uvicorn v3-copy:app --reload --host 0.0.0.0 --port 8000

The application will automatically train the model in the background as new users register.


📂 Project Structure

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

Pages

1. Main Page (Dashboard)

Main Page

  • 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.

2. Register Page (Enrollment)

Register Page

  • 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 keydown and keyup events, including dwell time and flight time calculations.

3. Login Page (Authentication)

Login Page

  • 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 HttpOnly sessions upon successful biometric verification.

After successfully logging in, the system will redirect you to a dashboard page.

📊 Data Structure & Feature Engineering

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: keydown or keyup.
  • 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.

⚠️ Data Leakage Prevention

Session-based grouping is enforced during train/validation split to prevent sliding-window leakage across sessions.

🛠️ Developer Tools

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.

🛡️ Security Features

  • 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.

About

No description, website, or topics provided.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

 
 
 

Contributors