Skip to content

About

AI-powered secure password vault with AES-256-GCM encryption, Django REST Framework, MongoDB, Redis and intelligent security analysis.

Resources

Security policy

Stars

1 star

Watchers

0 watching

Forks

Latest commit

Β 

History

14 Commits

Folders and files

Repository files navigation

πŸ” KeyVaultAI

AI-Assisted Secure Password Vault

Python Django Next.js TypeScript MongoDB Atlas Scikit-Learn Tests

KeyVaultAI is a secure, modern password manager built as a full-stack B.Tech project. It enables users to store credentials securely using authenticated server-side encryption, analyze password strength with a deterministic security engine, detect dangerous password reuse, and predict credential risk using machine learning.


πŸ“Έ Screenshots

Landing Page

KeyVaultAI Landing Page

Vault Dashboard

KeyVaultAI Vault Dashboard

The user interface is designed with a warm light glassmorphic aesthetic (#faf8f4), pastel sticky-note credential cards with 3D push-pin accents, and soft radiant borders.


✨ Features

πŸ”‘ Authentication & Security

  • User Authentication: Secure user registration, login, and logout.
  • Hybrid Token Security: Access tokens are kept in JavaScript memory only (never written to localStorage or sessionStorage); rotating refresh tokens are secured in an HttpOnly; Secure; SameSite=Strict cookie (kv_refresh) scoped strictly to auth endpoints with cross-origin credentials.
  • Argon2id Hashing: Account passwords hashed using OWASP-recommended parameters ($t=3$, $m=64\text{ MB}$, $p=4$) with timing-attack-safe dummy verification.
  • Email Verification & Self-Service Reset: Single-use, SHA-256-hashed tokens with URL hash fragment extraction (#token=...) ensuring tokens never appear in server referrer headers or browser history.
  • Legacy Account Safety: Unverified or legacy accounts fail closed at login and can request instant re-verification without modifying password hashes.
  • User Isolation (IDOR / BOLA Protected): Server-side ownership checks derive user identity strictly from verified JWT claims. Users can never view or manipulate another user's credentials.

πŸ—„οΈ Password Vault

  • AES-256-GCM Encryption: Stored credentials are encrypted with authenticated symmetric AES-256-GCM using fresh 12-byte random nonces per credential.
  • Full Credential CRUD: Add, view, edit, soft-delete, restore, and permanently delete credentials.
  • Reveal & Copy: Decrypt passwords on demand with authenticated owner-only verification.
  • Organization: Category filtering (General, Finance, Social, Work, etc.), favorites toggle, and private notes.
  • Safe Search: Instant search across non-sensitive metadata (website_name, username, email) with regex escaping.
  • Client-Side Validation: Pre-submission email validation to prevent invalid network requests.

πŸ›‘οΈ Security Analysis (Deterministic Engine)

  • Password Strength Scoring: Real-time evaluation (0–100) assessing length, diversity, character sets, and sequential patterns.
  • Classification: Categorizes passwords into Weak, Fair, Strong, and Very Strong.
  • Reuse Detection: Identifies duplicated passwords across a user's vault in-memory using ephemeral SHA-256 hashes (hashes are discarded immediately).

πŸ€– Machine Learning Engine

  • Vulnerability Risk Prediction: Scikit-learn classification pipeline (StandardScaler + LogisticRegression) trained on synthetic security data.
  • Risk Classification: Classifies passwords into LOW, MEDIUM, or HIGH risk levels.
  • Confidence & Explanation: Returns a probability score (0.0 – 1.0) and human-readable security advice.
  • Privacy-Preserving: Operates strictly on 9 numerical features extracted in-memory; plaintext passwords never enter model artifacts.

βš™οΈ Background Maintenance & Performance

  • Soft Deletion & Recovery: 72-hour restore window for soft-deleted credentials.
  • Automated Celery Cleanup: Separate Celery Worker and Beat services purge credentials after the 72-hour recovery window.
  • Email Account Flows: SMTP-backed verification and password reset use hashed, expiring, single-use tokens.
  • Fail-closed Rate Limits: Rate-limited actions are blocked when Redis cannot enforce limits.
  • Redis Rate Limiting: Atomic fixed-window limits on authentication and sensitive vault endpoints.

πŸ”„ Application Workflow

flowchart TD
    subgraph Client ["Client Layer"]
        User(["πŸ‘€ User"])
        Next["πŸ’» Next.js 15 Frontend"]
    end

    subgraph Backend ["Django REST Framework Backend"]
        API["πŸ“‘ REST API View"]
        JWT["πŸ”‘ JWT Authentication"]
        Owner["πŸ›‘οΈ User Ownership Check"]
        Val["βœ… Credential Validation"]
        
        subgraph Security ["Security & ML Analysis"]
            Sec["πŸ“Š Security Engine\n(Score, Strength & Reuse)"]
            MLFeat["🧠 In-Memory Feature Extraction"]
            MLModel["πŸ€– Scikit-Learn ML Model\n(LOW / MEDIUM / HIGH Risk)"]
        end
        
        Crypto["πŸ” AES-256-GCM Encryption\n(Fresh 12-byte Nonce)"]
    end

    subgraph Storage ["Database & Storage"]
        Atlas[("πŸƒ MongoDB Atlas\n(Encrypted Credential Docs)")]
    end

    subgraph Background ["Background Processing"]
        SoftDel["πŸ—‘οΈ Soft-Deleted Item\n(deleted_at timestamp)"]
        Beat["⏰ Celery Beat Scheduler"]
        Worker["βš™οΈ Celery Worker\n(72-Hour Cleanup Task)"]
        Purge(["❌ Permanent Deletion"])
    end

    User -->|Inputs Credential| Next
    Next -->|HTTPS REST + JWT| API
    API --> JWT
    JWT --> Owner
    Owner --> Val
    Val --> Sec
    Val --> MLFeat
    MLFeat --> MLModel
    Val --> Crypto
    Crypto -->|Store Ciphertext| Atlas

    Atlas -.->|Soft Delete| SoftDel
    Beat -->|Periodic Trigger| Worker
    SoftDel --> Worker
    Worker -->|Purge Expired Docs| Purge
Loading

πŸ› οΈ Tech Stack

Layer Technology Purpose
Frontend Next.js 15, React 19, TypeScript App Router, responsive component views, static generation
Styling Tailwind CSS 3.4, Framer Motion Glassmorphism, radiant border effects, animations
Backend Django 5.2, Django REST Framework REST APIs, authentication middleware, permission checks
Security Argon2-cffi, Cryptography (AES-256-GCM), PyJWT Password hashing, vault encryption, JWT token management
Machine Learning Scikit-Learn, NumPy Numerical feature extraction & logistic regression risk model
Database MongoDB Atlas (via PyMongo) Cloud document store for encrypted credentials and users
Cache & Broker Redis / Upstash Redis Rate limiting counters, token revocation, Celery message broker
Background Worker Celery 5.4 Separate Worker and Beat services; periodic 72-hour purge

πŸ”Œ API Overview

All API endpoints are under /api/v1/.

Group Method Endpoint Description
Auth POST /api/v1/auth/register/ Register a new user account (pending verification)
Auth POST /api/v1/auth/verify-email/ Verify user email with single-use hashed token
Auth POST /api/v1/auth/resend-verification/ Request a new email verification link
Auth POST /api/v1/auth/login/ Authenticate; returns access token & sets HttpOnly cookie
Auth POST /api/v1/auth/token/refresh/ Rotate refresh cookie & issue new access token
Auth POST /api/v1/auth/logout/ Revoke refresh token and clear auth cookie
Auth POST /api/v1/auth/forgot-password/ Request password reset email link
Auth POST /api/v1/auth/reset-password/ Reset account password using single-use token
Vault GET /api/v1/vault/credentials/ List all active credentials (metadata only)
Vault POST /api/v1/vault/credentials/ Encrypt and store a new credential
Vault POST /api/v1/vault/credentials/<id>/reveal/ Decrypt and reveal password (owner only)
Vault POST /api/v1/vault/credentials/<id>/copy/ Decrypt password for clipboard (audited)
Vault POST /api/v1/vault/credentials/<id>/soft-delete/ Move credential to Recently Deleted (72h window)
Vault GET /api/v1/vault/recently-deleted/ List soft-deleted credentials within 72h window
Vault POST /api/v1/vault/credentials/<id>/restore/ Restore soft-deleted credential
Vault DELETE /api/v1/vault/credentials/<id>/permanent-delete/ Permanently remove credential
Security GET /api/v1/security/summary/ Aggregate security score and health stats
Security GET /api/v1/security/credentials/ Detailed security metadata & reuse alerts
ML POST /api/v1/ml/predict/ Predict ML risk assessment (LOW/MED/HIGH)
Health GET /api/v1/health/ Service, database, and cache health check

πŸš€ Getting Started (Local Development)

1. Prerequisites

  • Python: 3.12+
  • Node.js: 18+ or 20+
  • MongoDB Atlas: Free cluster with your current IP allowlisted
  • Redis: Local Docker container or Upstash Redis instance

2. Clone the Repository

git clone https://github.com/shubhamjrd4559-sudo/KeyVaultAI.git
cd KeyVaultAI

3. Backend Setup

cd backend
python -m venv .venv

# Activate virtual environment:
# Windows (PowerShell):
.venv\Scripts\Activate.ps1
# Linux/macOS:
source .venv/bin/activate

pip install -r requirements.txt

Create a .env file in the backend/ directory from .env.example:

DJANGO_SECRET_KEY=your-dev-secret-key
JWT_SECRET_KEY=your-dev-jwt-secret-key
ENCRYPTION_KEY=your-32-byte-base64url-key
MONGODB_URI=mongodb+srv://<user>:<password>@<cluster>.mongodb.net/?retryWrites=true&w=majority
REDIS_URL=redis://localhost:6379/0
DEBUG=True

Tip: Generate keys easily in Python:

import secrets, os, base64
print("JWT/DJANGO:", secrets.token_urlsafe(64))
print("ENCRYPTION_KEY:", base64.urlsafe_b64encode(os.urandom(32)).decode())

Verify setup and run the Django backend:

python manage.py check
python manage.py runserver 127.0.0.1:8000

4. Frontend Setup

In a new terminal:

cd frontend
npm install
npm run dev

Open http://localhost:3000 to view the application.

5. Running Background Workers (Optional)

To test the 72-hour automated cleanup task locally:

# In backend directory with .venv active:
celery -A config worker --loglevel=INFO
celery -A config beat --loglevel=INFO

πŸ§ͺ Testing & Verification

The project includes unit, integration, and security isolation tests:

  • Backend Pytest Suite: 244 passed / 0 failed
    • Vault & Encryption (apps/vault/): 75 tests (AES-256-GCM roundtrips, tampering rejection, fresh nonces, 72h cleanup)
    • User Isolation (IDOR/BOLA): 33 dedicated tests proving cross-user access is denied under all tampering scenarios
    • Machine Learning Engine (apps/ml_engine/): 72 tests (feature extraction, LogisticRegression predictions, plaintext non-disclosure)
    • Security Engine (apps/security/): 46 tests (deterministic scoring, character variety, in-memory reuse detection)
    • Authentication & Email Flows (apps/users/): 63 tests (Argon2id hashing, timing attack safety, hybrid cookie auth, token rotation/revocation, single-use hashed verification & reset tokens, legacy accounts)
    • Common & Infrastructure (apps/common/): 3 tests (health probes, duplicate preflight index management command)
  • Django System Check: 0 issues identified
  • Frontend Typecheck (npx tsc --noEmit): 0 errors
  • Frontend Production Build (next build): Compiled successfully

Run backend tests:

cd backend
pytest -v

🌐 Deployment Plan

Current Local Development

  • Frontend: Local Next.js dev server on port 3000
  • Backend: Local Django dev server on port 8000
  • Database: MongoDB Atlas (cloud cluster)
  • Cache/Broker: Upstash Redis (cloud) or local Docker Redis

Planned Production Deployment

KeyVaultAI is currently run in development mode. Cloud production deployment is planned for Milestone 10.

  • Frontend: Vercel (Planned)
  • Backend: Railway (Planned, with Gunicorn WSGI)
  • Celery Worker & Beat: Railway (Planned background services)
  • Database: MongoDB Atlas (Configured for Dev / Planned for Prod)
  • Cache & Broker: Upstash Redis (Configured for Dev / Planned for Prod)

πŸ—ΊοΈ Project Milestones

  • Milestone 0: Repository setup, architecture planning, Docker Compose
  • Milestone 1: Django REST Framework baseline & health probes
  • Milestone 2: Authentication (Argon2id, JWT rotation, audit logging, rate limiting)
  • Milestone 3: Secure Vault (AES-256-GCM encryption, repositories, soft delete, Celery 72h purge)
  • Milestone 4: Frontend Integration (Next.js 15, sticky-notes UI, radiant borders, auth modal)
  • Milestone 5: Security Engine (Deterministic scoring, strength levels, in-memory reuse detection)
  • Milestone 6: Machine Learning Engine (Scikit-Learn LogisticRegression, risk prediction, privacy guarantees)
  • Milestone 7: NVIDIA NIM / AI Layer (Planned)
  • Milestone 8: Browser Extension for Chrome/Firefox (Planned)
  • Milestone 9: Full Ecosystem Integration (Planned)
  • Milestone 10: Production Cloud Hardening (Planned)

⚠️ Known Limitations

  • Email Configuration: Supply SMTP settings and the actual HTTPS frontend URL through the backend environment. No provider or credentials are bundled.
  • Token Storage: Hybrid model implemented β€” access tokens reside in JavaScript memory only; refresh tokens are stored in HttpOnly; Secure; SameSite=Strict cookies (kv_refresh) with automated rotation.
  • Background Cleanup: The automated 72-hour purge requires Celery Worker and Beat processes to be actively running.
  • Free-Trial Limits: Free-trial storage and credential quotas are configurable and will be finalized after architecture review (Status: Planned).

πŸ“œ License & Author

  • Author: Developed by SK (Shubham Kumar) β€” Project
  • License: Not yet specified.

🀝 Open Source Contributions

KeyVaultAI is an open project, and contributors are welcome.

If you are interested in improving the project, fixing bugs, adding features, improving documentation, or experimenting with new ideas, feel free to contribute.

Pull requests, suggestions, and constructive feedback are welcome. Please keep contributions focused and follow the existing project structure and coding practices.

About

AI-powered secure password vault with AES-256-GCM encryption, Django REST Framework, MongoDB, Redis and intelligent security analysis.

Resources

Security policy

Stars

1 star

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages