forked from menault/2026_TD2_DEV51_Qualite_Algo
td2
This commit is contained in:
+23
-9
@@ -35,10 +35,7 @@ def mention(moyenne):
|
||||
|
||||
|
||||
# Exercice P5
|
||||
def analyser_mot_de_passe(mdp, login=None):
|
||||
problemes = []
|
||||
if len(mdp) < 12:
|
||||
problemes.append("trop court")
|
||||
def categories_presentes(mdp):
|
||||
majuscule = minuscule = chiffre = special = False
|
||||
for c in mdp:
|
||||
if c.isupper():
|
||||
@@ -49,7 +46,26 @@ def analyser_mot_de_passe(mdp, login=None):
|
||||
chiffre = True
|
||||
else:
|
||||
special = True
|
||||
if not (majuscule and minuscule):
|
||||
return majuscule, minuscule, chiffre, special
|
||||
|
||||
|
||||
def melange_casses(majuscule, minuscule):
|
||||
return majuscule and minuscule
|
||||
|
||||
|
||||
def contient_repetition(mdp):
|
||||
for i in range(len(mdp) - 2):
|
||||
if mdp[i] == mdp[i + 1] == mdp[i + 2]:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def analyser_mot_de_passe(mdp, login=None):
|
||||
problemes = []
|
||||
if len(mdp) < 12:
|
||||
problemes.append("trop court")
|
||||
majuscule, minuscule, chiffre, special = categories_presentes(mdp)
|
||||
if not melange_casses(majuscule, minuscule):
|
||||
problemes.append("mélanger majuscules et minuscules")
|
||||
if not chiffre:
|
||||
problemes.append("ajouter un chiffre")
|
||||
@@ -57,10 +73,8 @@ def analyser_mot_de_passe(mdp, login=None):
|
||||
problemes.append("ajouter un caractère spécial")
|
||||
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 contient_repetition(mdp):
|
||||
problemes.append("éviter 3 caractères identiques")
|
||||
if not problemes:
|
||||
return "fort", []
|
||||
return ("moyen" if len(problemes) <= 2 else "faible"), problemes
|
||||
|
||||
Reference in New Issue
Block a user