forked from menault/2026_TD2_DEV51_Qualite_Algo
trois fonctions pour simplifier la complexité
This commit is contained in:
+17
-3
@@ -40,6 +40,16 @@ def analyser_mot_de_passe(mdp, login=None):
|
|||||||
if len(mdp) < 12:
|
if len(mdp) < 12:
|
||||||
problemes.append("trop court")
|
problemes.append("trop court")
|
||||||
majuscule = minuscule = chiffre = special = False
|
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:
|
for c in mdp:
|
||||||
if c.isupper():
|
if c.isupper():
|
||||||
majuscule = True
|
majuscule = True
|
||||||
@@ -49,21 +59,25 @@ def analyser_mot_de_passe(mdp, login=None):
|
|||||||
chiffre = True
|
chiffre = True
|
||||||
else:
|
else:
|
||||||
special = True
|
special = True
|
||||||
|
return [majuscule, minuscule, chiffre, special]
|
||||||
|
|
||||||
|
def verifyCharMix(problemes):
|
||||||
if not (majuscule and minuscule):
|
if not (majuscule and minuscule):
|
||||||
problemes.append("mélanger majuscules et minuscules")
|
problemes.append("mélanger majuscules et minuscules")
|
||||||
if not chiffre:
|
if not chiffre:
|
||||||
problemes.append("ajouter un chiffre")
|
problemes.append("ajouter un chiffre")
|
||||||
if not special:
|
if not special:
|
||||||
problemes.append("ajouter un caractère spécial")
|
problemes.append("ajouter un caractère spécial")
|
||||||
|
return problemes
|
||||||
|
|
||||||
|
def verifyPswdSafety(problemes):
|
||||||
if login and login.lower() in mdp.lower():
|
if login and login.lower() in mdp.lower():
|
||||||
problemes.append("ne pas contenir le login")
|
problemes.append("ne pas contenir le login")
|
||||||
for i in range(len(mdp) - 2):
|
for i in range(len(mdp) - 2):
|
||||||
if mdp[i] == mdp[i + 1] == mdp[i + 2]:
|
if mdp[i] == mdp[i + 1] == mdp[i + 2]:
|
||||||
problemes.append("éviter 3 caractères identiques")
|
problemes.append("éviter 3 caractères identiques")
|
||||||
break
|
break
|
||||||
if not problemes:
|
return problemes
|
||||||
return "fort", []
|
|
||||||
return ("moyen" if len(problemes) <= 2 else "faible"), problemes
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
|||||||
Reference in New Issue
Block a user