forked from menault/2026_TD2_DEV51_Qualite_Algo
TD2 : compte rendu complexité cyclomatique + refactorisation de P5
Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
@@ -0,0 +1,52 @@
|
||||
"""
|
||||
Refactorisation de P5 - analyser_mot_de_passe (M = 16 -> 4)
|
||||
"""
|
||||
|
||||
|
||||
def classer_caracteres(mdp):
|
||||
majuscule = minuscule = chiffre = special = False
|
||||
for c in mdp:
|
||||
if c.isupper():
|
||||
majuscule = True
|
||||
elif c.islower():
|
||||
minuscule = True
|
||||
elif c.isdigit():
|
||||
chiffre = True
|
||||
else:
|
||||
special = True
|
||||
return majuscule, minuscule, chiffre, special
|
||||
|
||||
|
||||
def contient_login(mdp, login):
|
||||
return bool(login) and login.lower() in mdp.lower()
|
||||
|
||||
|
||||
def a_trois_identiques(mdp):
|
||||
for i in range(len(mdp) - 2):
|
||||
if mdp[i] == mdp[i + 1] == mdp[i + 2]:
|
||||
return True
|
||||
return False
|
||||
|
||||
|
||||
def niveau(problemes):
|
||||
if not problemes:
|
||||
return "fort"
|
||||
return "moyen" if len(problemes) <= 2 else "faible"
|
||||
|
||||
|
||||
def analyser_mot_de_passe(mdp, login=None):
|
||||
majuscule, minuscule, chiffre, special = classer_caracteres(mdp)
|
||||
regles = [
|
||||
(len(mdp) < 12, "trop court"),
|
||||
(not (majuscule and minuscule), "mélanger majuscules et minuscules"),
|
||||
(not chiffre, "ajouter un chiffre"),
|
||||
(not special, "ajouter un caractère spécial"),
|
||||
(contient_login(mdp, login), "ne pas contenir le login"),
|
||||
(a_trois_identiques(mdp), "éviter 3 caractères identiques"),
|
||||
]
|
||||
problemes = [message for echec, message in regles if echec]
|
||||
return niveau(problemes), problemes
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
print(analyser_mot_de_passe("Motdepasse123!", "maxime"))
|
||||
Reference in New Issue
Block a user