Comment générer un mot de passe aléatoire en python
Vinay Kumar Shukla
Je veux utiliser python3
pour générer un mot de passe aléatoire pour crypter mes fichiers, le mot de passe aléatoire créé doit avoir la restriction suivante
- La longueur minimale doit être de 12
- Doit contenir une lettre majuscule.
- Doit contenir une lettre minuscule.
- Doit contenir un chiffre.
- Doit contenir un caractère spécial.
En fait, je ne sais pas grand-chose sur la génération de choses aléatoires python
avec des restrictions, donc je n'ai aucun code à afficher ici.
Oliver F
Vous pouvez choisir un caractère dans une liste avec la random
bibliothèque python . Voici un exemple:
import string
import random
symbols = ['*', '%', '£'] # Can add more
password = ""
for _ in range(9):
password += random.choice(string.ascii_lowercase)
password += random.choice(string.ascii_uppercase)
password += random.choice(string.digits)
password += random.choice(symbols)
print(password)