Add in proper passord check lib, show results in form

This commit is contained in:
2025-07-20 15:46:25 +01:00
parent 0127326b77
commit 2dae8b0ece
10 changed files with 1023 additions and 623 deletions

View File

@@ -134,38 +134,49 @@
});
function updatePasswordStrengthIndicator(password) {
// Simple client-side strength indicator
let strength = 0;
let feedback = [];
if (password.length >= 12) strength++;
else feedback.push('At least 12 characters');
if (/[A-Z]/.test(password)) strength++;
else feedback.push('Uppercase letter');
if (/[a-z]/.test(password)) strength++;
else feedback.push('Lowercase letter');
if (/\d/.test(password)) strength++;
else feedback.push('Number');
if (/[^a-zA-Z0-9]/.test(password)) strength++;
else feedback.push('Special character');
// Update visual indicator if it exists
const indicator = document.getElementById('password-strength-indicator');
if (indicator) {
if (!indicator) return;
if (password.length === 0) {
indicator.textContent = 'Enter password to see strength';
indicator.style.color = '#888';
return;
}
fetch('/api/password-strength', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({ password: password, username: document.getElementById('username').value }),
})
.then(response => response.json())
.then(data => {
if (data.error) {
indicator.textContent = 'Error checking strength';
indicator.style.color = '#ff4444';
return;
}
const strengthLevels = ['Very Weak', 'Weak', 'Fair', 'Good', 'Strong'];
const strengthColors = ['#ff4444', '#ff8800', '#ffaa00', '#88aa00', '#44aa44'];
indicator.textContent = strengthLevels[strength] || 'Very Weak';
indicator.style.color = strengthColors[strength] || '#ff4444';
if (feedback.length > 0) {
indicator.textContent += ' (Missing: ' + feedback.join(', ') + ')';
let displayLevel = data.strength_level;
let displayColor = strengthColors[strengthLevels.indexOf(data.strength_level)];
if (data.errors && data.errors.length > 0) {
displayLevel += ' (Missing: ' + data.errors.join(', ') + ')';
displayColor = '#ff4444'; // Indicate error with red color
}
}
indicator.textContent = displayLevel;
indicator.style.color = displayColor;
})
.catch(error => {
console.error('Error:', error);
indicator.textContent = 'Network Error';
indicator.style.color = '#ff4444';
});
}
// Clear password fields on page load for security