From a9902b95b43e67d93ad7066beb2e25426016bdc2 Mon Sep 17 00:00:00 2001 From: paul Date: Tue, 15 Jul 2025 18:47:31 +0200 Subject: [PATCH] fix: allow date formats as gallery passwords MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit - Modified backend password validation for galleries to be more lenient - Reduced minimum password length to 6 characters for galleries - Removed uppercase/lowercase/number requirements for gallery passwords - Allow date formats like "04.07.2025" as passwords - Added helper text to inform users about password options - Still prevent overly simple passwords like "123456" - Admin passwords remain strict with all security requirements 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude --- backend/src/utils/passwordValidation.js | 44 ++++++++++++++----- frontend/src/pages/admin/CreateEventPage.tsx | 4 ++ .../pages/admin/CreateEventPageEnhanced.tsx | 4 ++ 3 files changed, 41 insertions(+), 11 deletions(-) diff --git a/backend/src/utils/passwordValidation.js b/backend/src/utils/passwordValidation.js index 74c3d8b..1941348 100644 --- a/backend/src/utils/passwordValidation.js +++ b/backend/src/utils/passwordValidation.js @@ -111,7 +111,39 @@ function validatePassword(password, options = {}) { * @returns {Object} - Validation result */ function validatePasswordInContext(password, context, userData = {}) { - // Base validation + // For gallery context, use more lenient validation + if (context === 'gallery') { + // Gallery-specific validation options + const galleryOptions = { + minLength: 6, // Reduced minimum length + requireUppercase: false, // Don't require uppercase for galleries + requireLowercase: false, // Don't require lowercase for galleries + requireNumbers: false, // Numbers are optional + requireSpecialChars: false, // Special chars are optional + preventCommonPasswords: true, // Still prevent common passwords + minStrengthScore: 0 // Accept any score for galleries + }; + + // Base validation with gallery-specific options + const result = validatePassword(password, galleryOptions); + + // 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; + result.errors.push('Password cannot be just numbers. Consider using a date format like "04.07.2025"'); + } + + return result; + } + + // Base validation for other contexts const result = validatePassword(password); // Context-specific validation @@ -136,16 +168,6 @@ function validatePasswordInContext(password, context, userData = {}) { result.errors.push('Password must not contain parts of your email'); } } - } else if (context === 'gallery') { - // Gallery passwords can be more lenient for user convenience - // Allow passwords with score >= 1 (weak but acceptable) - if (result.score < 1) { - result.valid = false; - result.errors.push('Password is too simple. Please add more complexity'); - } - - // Don't check for event name in password - allow date-based passwords - // This allows passwords like "Sommer2025!" which users prefer } return result; diff --git a/frontend/src/pages/admin/CreateEventPage.tsx b/frontend/src/pages/admin/CreateEventPage.tsx index de32a2d..d635c19 100644 --- a/frontend/src/pages/admin/CreateEventPage.tsx +++ b/frontend/src/pages/admin/CreateEventPage.tsx @@ -204,6 +204,9 @@ export const CreateEventPage: React.FC = () => { newErrors.password = t('validation.passwordRequired'); } else if (formData.password.length < 6) { newErrors.password = t('validation.passwordMinLength'); + } else if (/^\d{1,6}$/.test(formData.password)) { + // Prevent simple numeric passwords like "123456" + newErrors.password = t('validation.passwordTooSimple', 'Password cannot be just numbers. Consider using a date format like "04.07.2025"'); } if (formData.password !== formData.confirm_password) { @@ -412,6 +415,7 @@ export const CreateEventPage: React.FC = () => { onChange={handleInputChange('password')} error={errors.password} placeholder={t('events.enterPassword')} + helperText={t('events.passwordHelperText', 'You can use dates like "04.07.2025" or any text with 6+ characters')} leftIcon={} className="pr-10" /> diff --git a/frontend/src/pages/admin/CreateEventPageEnhanced.tsx b/frontend/src/pages/admin/CreateEventPageEnhanced.tsx index 75d1765..fe1a5e6 100644 --- a/frontend/src/pages/admin/CreateEventPageEnhanced.tsx +++ b/frontend/src/pages/admin/CreateEventPageEnhanced.tsx @@ -180,6 +180,9 @@ export const CreateEventPageEnhanced: React.FC = () => { newErrors.password = t('validation.passwordRequired'); } else if (formData.password.length < 6) { newErrors.password = t('validation.passwordMinLength'); + } else if (/^\d{1,6}$/.test(formData.password)) { + // Prevent simple numeric passwords like "123456" + newErrors.password = t('validation.passwordTooSimple', 'Password cannot be just numbers. Consider using a date format like "04.07.2025"'); } if (formData.password !== formData.confirm_password) { @@ -453,6 +456,7 @@ export const CreateEventPageEnhanced: React.FC = () => { value={formData.password} onChange={handleInputChange('password')} error={errors.password} + helperText={t('events.passwordHelperText', 'You can use dates like "04.07.2025" or any text with 6+ characters')} leftIcon={} rightIcon={