UNPKG

fortify2-js

Version:

MOST POWERFUL JavaScript Security Library! Military-grade cryptography + 19 enhanced object methods + quantum-resistant algorithms + perfect TypeScript support. More powerful than Lodash with built-in security.

66 lines (62 loc) 1.84 kB
'use strict'; require('crypto'); /** * Security Utilities for FortifyJS * Enhanced security functions for robust cryptographic operations */ /** * Rate limiting utility for security operations */ class SecurityRateLimiter { constructor(maxAttempts = 5, windowMs = 300000) { this.attempts = new Map(); this.maxAttempts = maxAttempts; this.windowMs = windowMs; } /** * Check if operation is allowed for the given identifier * @param identifier - Unique identifier (e.g., IP address, user ID) * @returns True if operation is allowed */ isAllowed(identifier) { const now = Date.now(); const record = this.attempts.get(identifier); if (!record) { this.attempts.set(identifier, { count: 1, lastAttempt: now }); return true; } // Reset if window has passed if (now - record.lastAttempt > this.windowMs) { this.attempts.set(identifier, { count: 1, lastAttempt: now }); return true; } // Check if limit exceeded if (record.count >= this.maxAttempts) { return false; } // Increment counter record.count++; record.lastAttempt = now; return true; } /** * Reset attempts for an identifier * @param identifier - Identifier to reset */ reset(identifier) { this.attempts.delete(identifier); } /** * Clean up old entries */ cleanup() { const now = Date.now(); for (const [key, record] of this.attempts.entries()) { if (now - record.lastAttempt > this.windowMs) { this.attempts.delete(key); } } } } exports.SecurityRateLimiter = SecurityRateLimiter; //# sourceMappingURL=securityUtils.js.map