Maj Section Général

This commit is contained in:
2026-06-15 23:03:37 +02:00
parent 01526a5551
commit 032a370e7d
15 changed files with 492 additions and 57 deletions
+7 -4
View File
@@ -7,13 +7,15 @@
* Affiche uniquement quand password est non vide.
*/
const RULES = [
{ id: 'len', label: '8 caractères minimum', test: p => p.length >= 8 },
function buildRules(minLen) {
return [
{ id: 'len', label: `${minLen} caractères minimum`, test: p => p.length >= minLen },
{ id: 'upper', label: 'Une lettre majuscule (AZ)', test: p => /[A-Z]/.test(p) },
{ id: 'lower', label: 'Une lettre minuscule (az)', test: p => /[a-z]/.test(p) },
{ id: 'digit', label: 'Un chiffre (09)', test: p => /[0-9]/.test(p) },
{ id: 'special', label: 'Un caractère spécial (!@#…)', test: p => /[^A-Za-z0-9]/.test(p) },
];
];
}
const LEVELS = [
{ min: 0, label: 'Très faible', color: '#ef4444' },
@@ -32,9 +34,10 @@ function getLevel(score) {
return LEVELS[0];
}
export default function PasswordStrength({ password }) {
export default function PasswordStrength({ password, minLength = 8 }) {
if (!password) return null;
const RULES = buildRules(minLength);
const results = RULES.map(r => ({ ...r, ok: r.test(password) }));
const score = results.filter(r => r.ok).length;
const level = getLevel(score);