resolution du tp

This commit is contained in:
2026-10-14 12:34:08 +02:00
parent cecf7379f6
commit ac6946e442
9 changed files with 74 additions and 16 deletions
+43 -16
View File
@@ -33,39 +33,66 @@ def mention(moyenne):
return libelle
return "Ajourné"
def analyser_caractere(c,majuscule,minuscule,chiffre,special):
# Exercice P5
def analyser_mot_de_passe(mdp, login=None):
problemes = []
if len(mdp) < 12:
if c.isupper():
majuscule = True
elif c.islower():
minuscule = True
elif c.isdigit():
chiffre = True
else:
special = True
return majuscule,minuscule,chiffre,special
def verif_petit(len, problemes):
if len <12:
problemes.append("trop court")
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
if not (majuscule and minuscule):
def verif_no_min_maj(min,maj,problemes):
if not (maj and min):
problemes.append("mélanger majuscules et minuscules")
def verif_chiffre(chiffre,problemes):
if not chiffre:
problemes.append("ajouter un chiffre")
def verif_special(special,problemes):
if not special:
problemes.append("ajouter un caractère spécial")
def verif_mdp_is_not_login(login,mdp,problemes):
if login and login.lower() in mdp.lower():
problemes.append("ne pas contenir le login")
def verif_carac_identique(mdp,problemes):
for i in range(len(mdp) - 2):
if mdp[i] == mdp[i + 1] == mdp[i + 2]:
problemes.append("éviter 3 caractères identiques")
break
return
def verif_fort(problemes):
if not problemes:
return "fort", []
return ("moyen" if len(problemes) <= 2 else "faible"), problemes
def analyser_mot_de_passe(mdp, login=None):
problemes = []
majuscule = minuscule = chiffre = special = False
for c in mdp:
majuscule,minuscule,chiffre,special = analyser_caractere(c,majuscule,minuscule,chiffre,special)
print(majuscule,minuscule,chiffre,special)
verif_petit(len(mdp), problemes)
verif_no_min_maj(minuscule,majuscule,problemes)
verif_chiffre(chiffre,problemes)
verif_special(special,problemes)
verif_mdp_is_not_login(login,mdp,problemes)
verif_carac_identique(mdp,problemes)
return verif_fort(problemes)
if __name__ == "__main__":
print(celsius_vers_fahrenheit(20), signe(-3), notes_valides([12, 25, -1, 8]),
mention(13.5), analyser_mot_de_passe("Motdepasse123!", "maxime"))