Maj Section Général
This commit is contained in:
@@ -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 (A–Z)', test: p => /[A-Z]/.test(p) },
|
||||
{ id: 'lower', label: 'Une lettre minuscule (a–z)', test: p => /[a-z]/.test(p) },
|
||||
{ id: 'digit', label: 'Un chiffre (0–9)', 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);
|
||||
|
||||
Reference in New Issue
Block a user