mdp_aleatoires.py

Created by elnix90

Created on March 15, 2023

1.63 KB

Ce programme génère une mot de passe aléatoire. Par défaut, il y aura 1 mot de passe de 12 caractères mais si vous en voulez plus, vous pouvez renseigner deux variables dans la fonction mdp(): x, le nombre de caractères et y, le nombre de mots de passes générés. J’espère que mon programme vous plaira, dites moi ce que vous en pensez sur discord: Elnix90#0116


from random import *
print("mdp()")
def mdp(x=12,y=1):
  for i in range(y):
    minuscules  = ["a","b","c","d","e","f","g","h","i","j","k","l","m","n","o","p","q","r","s","t","u","v","w","x","y","z"]
    majuscules  = ["A","B","C","D","E","F","G","H","I","J","K","L","M","N","O","P","Q","R","S","T","U","V","W","X","Y","Z"]
    chiffres    = ["0","1","2","3","4","5","6","7","8","9"]
    symboles    = ["_","<",">","&","#","%","-","+","/","*","="]
    ponctuation = ["?","!",".",":",";",'"',"'",",","(",")","[","]","{","}"]
    TotalMinuscules  = 0
    TotalMajuscules  = 0
    TotalChiffres    = 0
    TotalSymboles    = 0
    TotalPonctuation = 0
    MaxTotalMinuscules  = x//4
    MaxTotalMajuscules  = x//4
    MaxTotalChiffres    = x//4
    MaxTotalSymboles    = x//4
    MaxTotalPonctuation = x-((x//4)*4)
    Caracteres = []
    ChoixChars = ""
    MotDePasse = ""
    for i in range(x):
      if TotalMinuscules<MaxTotalMinuscules:
        Caracteres.append(choice(minuscules))
        TotalMinuscules += 1
      if TotalMajuscules<MaxTotalMajuscules:
        Caracteres.append(choice(majuscules))
        TotalMajuscules += 1
      if TotalChiffres<MaxTotalChiffres:
        Caracteres.append(choice(chiffres))
        TotalChiffres += 1
      if TotalPonctuation<MaxTotalPonctuation:
        Caracteres.append(choice(ponctuation))
        TotalPonctuation += 1
      if TotalSymboles<MaxTotalSymboles:
        Caracteres.append(choice(symboles))
        TotalSymboles += 1
    for i in range(x):
      ChoixChars = choice(Caracteres)
      MotDePasse += ChoixChars
      Caracteres.remove(ChoixChars)
    print(MotDePasse)
    MotDePasse = ""

During your visit to our site, NumWorks needs to install "cookies" or use other technologies to collect data about you in order to:

With the exception of Cookies essential to the operation of the site, NumWorks leaves you the choice: you can accept Cookies for audience measurement by clicking on the "Accept and continue" button, or refuse these Cookies by clicking on the "Continue without accepting" button or by continuing your browsing. You can update your choice at any time by clicking on the link "Manage my cookies" at the bottom of the page. For more information, please consult our cookies policy.