trois fonctions pour simplifier la complexité

This commit is contained in:
camille
2026-10-14 14:00:35 +02:00
parent cd45b86ea1
commit c136e1a30a
+17 -3
View File
@@ -40,6 +40,16 @@ def analyser_mot_de_passe(mdp, login=None):
if len(mdp) < 12:
problemes.append("trop court")
majuscule = minuscule = chiffre = special = False
kindOfLetter(mdp)
verifyCharMix(problemes)
verifyPswdSafety(problemes)
if not problemes:
return "fort", []
return ("moyen" if len(problemes) <= 2 else "faible"), problemes
def kindOfLetter(mdp):
for c in mdp:
if c.isupper():
majuscule = True
@@ -49,21 +59,25 @@ def analyser_mot_de_passe(mdp, login=None):
chiffre = True
else:
special = True
return [majuscule, minuscule, chiffre, special]
def verifyCharMix(problemes):
if not (majuscule and minuscule):
problemes.append("mélanger majuscules et minuscules")
if not chiffre:
problemes.append("ajouter un chiffre")
if not special:
problemes.append("ajouter un caractère spécial")
return problemes
def verifyPswdSafety(problemes):
if login and login.lower() in mdp.lower():
problemes.append("ne pas contenir le login")
for i in range(len(mdp) - 2):
if mdp[i] == mdp[i + 1] == mdp[i + 2]:
problemes.append("éviter 3 caractères identiques")
break
if not problemes:
return "fort", []
return ("moyen" if len(problemes) <= 2 else "faible"), problemes
return problemes
if __name__ == "__main__":