Ajoute code et documents du TP générateur de mots de passe
This commit is contained in:
parent
fc5c154ac7
commit
9cdc849095
7 changed files with 7930 additions and 1 deletions
0
src/cours/CIEL1/01-bases-python/tp/TP_MDP04_fichiers.md
Normal file
0
src/cours/CIEL1/01-bases-python/tp/TP_MDP04_fichiers.md
Normal file
|
|
@ -1,3 +1,5 @@
|
||||||
|
from pathlib import Path
|
||||||
|
|
||||||
WORDS = {
|
WORDS = {
|
||||||
"11111": "abacus",
|
"11111": "abacus",
|
||||||
"11112": "abdomen",
|
"11112": "abdomen",
|
||||||
|
|
@ -7781,4 +7783,12 @@ def get_word_list():
|
||||||
return list(WORDS.values())
|
return list(WORDS.values())
|
||||||
|
|
||||||
def get_word_dict():
|
def get_word_dict():
|
||||||
return WORDS
|
return WORDS
|
||||||
|
|
||||||
|
def get_words_from_file():
|
||||||
|
file_path = Path("eff_words_long_list.txt")
|
||||||
|
with file_path.open('r') as file:
|
||||||
|
lines = file.readlines()
|
||||||
|
|
||||||
|
words = {line.split("\t")[0].strip():line.split("\t")[1].strip() for line in lines}
|
||||||
|
return words
|
||||||
7776
src/cours/CIEL1/01-bases-python/tp/code/eff_words_long_list.txt
Normal file
7776
src/cours/CIEL1/01-bases-python/tp/code/eff_words_long_list.txt
Normal file
File diff suppressed because it is too large
Load diff
41
src/cours/CIEL1/01-bases-python/tp/code/main.py
Normal file
41
src/cours/CIEL1/01-bases-python/tp/code/main.py
Normal file
|
|
@ -0,0 +1,41 @@
|
||||||
|
import mdp
|
||||||
|
|
||||||
|
def afficher_menu():
|
||||||
|
print("================================================")
|
||||||
|
print("CIEL - Générateur de mots de passe")
|
||||||
|
print("================================================")
|
||||||
|
print("Quel type de mot de passe souhaitez-vous créer ?")
|
||||||
|
print("1 - Mot de passe avec configuration par défaut")
|
||||||
|
print("2 - Mot de passe avec configuration personnalisée")
|
||||||
|
print("3 - Phrase de passe avec configuration par défaut")
|
||||||
|
print("4 - Phrase de passe avec configuration personnalisée")
|
||||||
|
print("0 - Quitter")
|
||||||
|
|
||||||
|
def choix_generateur(choix):
|
||||||
|
match choix:
|
||||||
|
case 1:
|
||||||
|
print(mdp.generer_mdp_with_constraints())
|
||||||
|
case 2:
|
||||||
|
print(mdp.generer_mdp_personnalise())
|
||||||
|
case 3:
|
||||||
|
print(mdp.generer_passphrase_v1())
|
||||||
|
case 4:
|
||||||
|
print(mdp.generer_passphrase_personnalise())
|
||||||
|
case 0:
|
||||||
|
print("Vous quittez le programme")
|
||||||
|
case _ as action:
|
||||||
|
print(f"Erreur : l'option {action} n'existe pas")
|
||||||
|
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
choix = -1
|
||||||
|
while choix != 0:
|
||||||
|
afficher_menu()
|
||||||
|
choix = int(input("Saisissez votre choix : "))
|
||||||
|
choix_generateur(choix)
|
||||||
|
if choix != 0 :
|
||||||
|
input("Appuyez sur Entrée")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
69
src/cours/CIEL1/01-bases-python/tp/code/mdp.py
Normal file
69
src/cours/CIEL1/01-bases-python/tp/code/mdp.py
Normal file
|
|
@ -0,0 +1,69 @@
|
||||||
|
import secrets
|
||||||
|
import string
|
||||||
|
|
||||||
|
from eff_words import get_word_list, get_words_from_file
|
||||||
|
|
||||||
|
LETTRES = string.ascii_letters
|
||||||
|
CHIFFRES = string.digits
|
||||||
|
SPECIAL = string.punctuation
|
||||||
|
|
||||||
|
ALPHABET = LETTRES + CHIFFRES + SPECIAL
|
||||||
|
|
||||||
|
DICE_NB = 5
|
||||||
|
|
||||||
|
def generer_mdp(password_length = 14):
|
||||||
|
password = ""
|
||||||
|
for i in range(password_length):
|
||||||
|
password += secrets.choice(ALPHABET)
|
||||||
|
return password
|
||||||
|
|
||||||
|
def generer_mdp_with_constraints(password_length = 14, special = 1, digits = 1):
|
||||||
|
password = ""
|
||||||
|
contrainte_special_respectee = False
|
||||||
|
contrainte_digits_respectee = False
|
||||||
|
while not (contrainte_special_respectee and contrainte_digits_respectee):
|
||||||
|
password = generer_mdp(password_length=password_length)
|
||||||
|
contrainte_special_respectee = sum(char in SPECIAL for char in password) >= special
|
||||||
|
contrainte_digits_respectee = sum(char in CHIFFRES for char in password) >= digits
|
||||||
|
return password
|
||||||
|
|
||||||
|
def generer_mdp_personnalise():
|
||||||
|
password_length = int(input("Longueur du mot de passe: "))
|
||||||
|
return generer_mdp(password_length=password_length)
|
||||||
|
|
||||||
|
def generer_passphrase_v1(nb_words = 6):
|
||||||
|
words = get_word_list()
|
||||||
|
|
||||||
|
chosen_words = []
|
||||||
|
for _ in range(nb_words):
|
||||||
|
next_word = secrets.choice(words)
|
||||||
|
chosen_words.append(next_word)
|
||||||
|
|
||||||
|
return '-'.join(chosen_words)
|
||||||
|
|
||||||
|
def generer_passphrase_v2(nb_words = 6, add_digit=False, capitalize=True, sep='-'):
|
||||||
|
words = get_words_from_file()
|
||||||
|
|
||||||
|
chosen_words = []
|
||||||
|
for _ in range(nb_words):
|
||||||
|
dice = "".join(str(secrets.randbelow(6) + 1) for _ in range(DICE_NB))
|
||||||
|
next_word = words[dice]
|
||||||
|
if capitalize:
|
||||||
|
next_word = next_word.capitalize()
|
||||||
|
if add_digit:
|
||||||
|
next_word+=secrets.choice(CHIFFRES+SPECIAL)
|
||||||
|
chosen_words.append(next_word)
|
||||||
|
|
||||||
|
return sep.join(chosen_words)
|
||||||
|
|
||||||
|
def generer_passphrase_personnalise():
|
||||||
|
nb_words = int(input("Nombre de mots : "))
|
||||||
|
add_digit = input("Ajouter des chiffres ou caractères spéciaux ? (y/n) : ") in ["y","Y"]
|
||||||
|
capitalize = input("Ajouter une majuscule au début des mots ? (y/n) : ") in ["y","Y"]
|
||||||
|
sep = input("Séparateur de mots : ")
|
||||||
|
return generer_passphrase_v2(
|
||||||
|
nb_words=nb_words,
|
||||||
|
add_digit=add_digit,
|
||||||
|
capitalize=capitalize,
|
||||||
|
sep=sep
|
||||||
|
)
|
||||||
Binary file not shown.
33
src/cours/CIEL2/01-revisions-python/tp/code/main.py
Normal file
33
src/cours/CIEL2/01-revisions-python/tp/code/main.py
Normal file
|
|
@ -0,0 +1,33 @@
|
||||||
|
if __name__ == "__main__":
|
||||||
|
choix = None
|
||||||
|
while choix != 0:
|
||||||
|
print("================================================")
|
||||||
|
print("CIEL - Générateur de mots de passe")
|
||||||
|
print("================================================")
|
||||||
|
print("Quel type de mot de passe souhaitez-vous créer ?")
|
||||||
|
print("1 - Mot de passe avec configuration par défaut")
|
||||||
|
print("2 - Mot de passe avec configuration personnalisée")
|
||||||
|
print("3 - Phrase de passe avec configuration par défaut")
|
||||||
|
print("4 - Phrase de passe avec configuration personnalisée")
|
||||||
|
print("0 - Quitter\n")
|
||||||
|
|
||||||
|
|
||||||
|
choix = int(input("Saisissez votre choix : "))
|
||||||
|
|
||||||
|
print("\n")
|
||||||
|
match choix:
|
||||||
|
case 1:
|
||||||
|
print("Mot de passe par défaut")
|
||||||
|
case 2:
|
||||||
|
print("Mot de passe personnalisé")
|
||||||
|
case 3:
|
||||||
|
print("Phrase de passe par défaut")
|
||||||
|
case 4:
|
||||||
|
print("Phrase de passe personnalisée")
|
||||||
|
case 0:
|
||||||
|
print("Vous quittez le programme")
|
||||||
|
case _:
|
||||||
|
print(f"Erreur : l'option {choix} n'existe pas")
|
||||||
|
|
||||||
|
if choix != 0 :
|
||||||
|
input("\n\nAppuyez sur Entrée")
|
||||||
Loading…
Add table
Add a link
Reference in a new issue