-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpassword_generator.py
More file actions
28 lines (20 loc) · 895 Bytes
/
password_generator.py
File metadata and controls
28 lines (20 loc) · 895 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
import random
import string
def generer_mot_de_passe(longueur):
if longueur < 4:
print("La longueur doit être d'au moins 4.")
return ""
minuscule = random.choice(string.ascii_lowercase)
majuscule = random.choice(string.ascii_uppercase)
chiffre = random.choice(string.digits)
symbole = random.choice(string.punctuation)
tous_les_caracteres = string.ascii_letters + string.digits + string.punctuation
reste = [random.choice(tous_les_caracteres) for _ in range(longueur - 4)]
mot_de_passe_liste = [minuscule, majuscule, chiffre, symbole] + reste
random.shuffle(mot_de_passe_liste)
return "".join(mot_de_passe_liste)
if __name__ == '__main__':
longueur = int(input("Longueur du mot de passe : "))
mot_de_passe = generer_mot_de_passe(longueur)
if mot_de_passe != "":
print("Mot de passe généré :", mot_de_passe)