diff --git a/backend/src/utils/passwordValidation.js b/backend/src/utils/passwordValidation.js index 1941348..4274cfd 100644 --- a/backend/src/utils/passwordValidation.js +++ b/backend/src/utils/passwordValidation.js @@ -78,6 +78,16 @@ function validatePassword(password, options = {}) { } } + // Skip zxcvbn check if explicitly disabled (for gallery passwords) + if (options.skipStrengthCheck) { + return { + valid: errors.length === 0, + errors, + score: 2, // Default moderate score for gallery passwords + feedback: {} + }; + } + // Use zxcvbn for strength analysis const strength = zxcvbn(password); @@ -121,19 +131,32 @@ function validatePasswordInContext(password, context, userData = {}) { requireNumbers: false, // Numbers are optional requireSpecialChars: false, // Special chars are optional preventCommonPasswords: true, // Still prevent common passwords - minStrengthScore: 0 // Accept any score for galleries + minStrengthScore: 0, // Accept any score for galleries + skipStrengthCheck: true // Skip zxcvbn strength analysis for galleries }; // Base validation with gallery-specific options const result = validatePassword(password, galleryOptions); + // Override validation for common date formats + // Allow passwords like "04.07.2025", "04/07/2025", "04-07-2025" + const datePattern = /^\d{1,2}[.\/-]\d{1,2}[.\/-]\d{4}$/; + if (datePattern.test(password)) { + // Date format is valid for gallery passwords + return { + valid: true, + errors: [], + score: 2, + feedback: {} + }; + } + // Additional gallery-specific checks if (password.length < 6) { result.valid = false; result.errors = ['Password must be at least 6 characters long']; } - // Allow date-based passwords like "04.07.2025" // Check if it's too simple (e.g., just "123456") if (/^\d{1,6}$/.test(password)) { result.valid = false;