Advertisement
Dar954826

Password Nuovo[ITA].py

Feb 1st, 2015
168
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 6.05 KB | None | 0 0
  1. def clsdir():
  2.  import os,glob
  3.  lll=""
  4.  g=glob.glob("*.txt")
  5.  gg=len(g)-1
  6.  ggg=0
  7.  while True:
  8.   if ggg==gg+1:
  9.    print("\n"*1000)
  10.    print("Non è stato utilizzato alcun dizionario")
  11.    no()
  12.   while lll!="Y" and lll!="N" and lll!="y" and lll!="n":
  13.    lll=input("Utilizzare "+g[ggg]+" come dizionario?[Y/N]")
  14.   if lll=="y" or lll=="Y":
  15.    if g[ggg]=="dic.txt":
  16.     psw()
  17.    else:
  18.     break
  19.   else:
  20.    ggg=ggg+1
  21.    lll=""
  22.  if os.path.exists(g[ggg]):
  23.   d=open(g[ggg],"r")
  24.   a=d.read()
  25.   b=input("Inserire separatore parole:[n=a capo]")
  26.   try:
  27.    if b=="":
  28.     6/0
  29.   except ZeroDivisionError:
  30.    b=input("Devi inserire un separatore, se non esiste lasciare digitare INVIO senza scrivere niente: ")
  31.    if b=="":
  32.      psw()
  33.   if b=="n":
  34.    b="\n"
  35.   a=a.replace(b,"|")
  36.   k=open("dic.txt","x")
  37.   k.write(a)
  38.  
  39. def no():
  40.   import random,string
  41.   pas=set1=set2=set3=set4=set5=log=""
  42.   while set1!="n" and set1!="N" and set1!="Y" and set1!="y":
  43.    set1=input("Inserire numeri?[Y/N]")
  44.    set1=set1.upper()
  45.   while set2!="n" and set2!="N" and set2!="Y" and set2!="y":
  46.    set2=input("Inserire lettere minuscole?[Y/N]")
  47.    set2=set2.upper()
  48.   while set3!="n" and set3!="N" and set3!="Y" and set3!="y":
  49.    set3=input("Inserire maiuscole?[Y/N]")
  50.    set3=set3.upper()
  51.   while set4!="n" and set4!="N" and set4!="Y" and set4!="y":
  52.    set4=input("Inserire caratteri speciali?[Y/N]")
  53.    set4=set4.upper()
  54.   try:
  55.    set5=int(input("Inserire lunghezza password: "))
  56.   except ValueError:
  57.    set5=4
  58.   try:
  59.    set6=int(input("Inserire password da generare: "))
  60.   except ValueError:
  61.    set6=1
  62.   if set1=="N" and set2=="N" and set3=="N" and set4=="N" :
  63.    set1="Y"
  64.   for j in range(set6):
  65.    while len(pas)!=set5:
  66.     rndset=random.randint(1,4)
  67.     if rndset==1 and set1=="Y":
  68.      log=random.randint(1,10)
  69.      log=string.digits[log-1]
  70.     if rndset==2 and set2=="Y":
  71.      log=random.randint(1,26)
  72.      log=string.ascii_lowercase[log-1]
  73.     if rndset==3 and set3=="Y":
  74.      log=random.randint(1,26)
  75.      log=string.ascii_uppercase[log-1]
  76.     if rndset==4 and set4=="Y":
  77.      log=random.randint(1,32)
  78.      log=string.punctuation[log-1]
  79.     pas=pas+log
  80.     log=""
  81.    print(pas)
  82.    pas=""
  83. def psw():
  84.  
  85.  import random,os,string
  86.  b=n=""
  87.  z=[]
  88.  if os.path.exists("dic.txt"):
  89.   try:
  90.    a=open("dic.txt","r")
  91.   except MemoryError:
  92.    import random
  93.    gdkj=random.randint(0,9999999999)
  94.    gdkj="dic"+str(gdkj)+".txt"
  95.    print("Questo dizionario non può essere utilizzato")
  96.    os.rename("dic.txt",gdkj)
  97.    b="N"
  98.   cache=a.read()
  99.   cache=cache.split("|")
  100.   if len(cache)==1:
  101.    a.close()
  102.    try:
  103.     6/0
  104.    except ZeroDivisionError:
  105.     import random
  106.     gdkj=random.randint(0,9999999999)
  107.     gdkj="dic"+str(gdkj)+".txt"
  108.     print("Questo dizionario non può essere utilizzato")
  109.     os.rename("dic.txt",gdkj)
  110.     b="N"
  111.   while b!="Y" and b!="n" and b!="N" and b!="y" and b!=00:
  112.    b=input("Utilizzare questo dizionario?[Y/N] ")
  113.   if b=="y"or b=="Y":
  114.    try:
  115.     k=int(input("Inserire numero parole: "))
  116.     if k<0:
  117.      6/0
  118.    except ValueError:
  119.     k=1
  120.    except ZeroDivisionError:
  121.     k=1
  122.    kk=input("Inserire separatore parole: ")
  123.    kkk=int(input("Inserire numero password: "))
  124.    for tm in range(kkk):
  125.     for m in range(k):
  126.      b=random.randint(1,len(cache))
  127.      b=cache[b-1]
  128.      if n!="":
  129.       n=n+kk+b
  130.      else:
  131.       n=n+b
  132.     print(n)
  133.     n=""
  134.     #---------------
  135.   else:
  136.    no()
  137.  else:
  138.   no()
  139.  input("Clicca per continuare")
  140.  print("\n"*1000)
  141.  
  142.  
  143. def algos():
  144.  try:
  145.   import os,random,string
  146.   a=b=c=d=var=code=finish=""
  147.   e=f=0
  148.   dic=[]
  149.   print("n = Numeri")
  150.   print("u = Maiuscole")
  151.   print("c = Minuscole")
  152.   print("l = Speciali")
  153.   print("p = personali")
  154.   print("s = separatore")
  155.   print("Inserire anche il numero di caratteri")
  156.   print("Esempio codice: 2n3c")
  157.   print("Esso genererà password con 2 numeri e 3 lettere minuscole")
  158.   a=input("Inserire codice: ")
  159.   a=a.lower()
  160.   error="abdefghijkmoqrtvwxyz"
  161.   for err in error:
  162.    if a.count(err)!=0:
  163.     6/0
  164.    if a.count("n")==0 and a.count("u")==0 and a.count("c")==0 and a.count("l")==0 and a.count("p")==0 and a.count("s")==0:
  165.     6/0
  166.   if a.count("s")!=0:
  167.    b=input("Inserire separatore: ")
  168.   if a.count("p")!=0:
  169.    c=input("Inserire caratteri personali: ")
  170.   d=input("Inserire numero password: ")
  171.   if d=="":
  172.    d="1"
  173.   while True:
  174.    if e==len(a):
  175.     break
  176.    else:
  177.     if a[e]=="0" or a[e]=="1" or a[e]=="2" or a[e]=="3" or a[e]=="4" or a[e]=="5" or a[e]=="6" or a[e]=="7" or a[e]=="8" or a[e]=="9":
  178.      var=var+a[e]
  179.     else:
  180.      try:
  181.       code=code+(a[e]*int(var))
  182.      except ValueError:
  183.       code=code+(a[e]*1)
  184.      var=""
  185.     e=e+1
  186.   for kk in range(int(d)):
  187.    finish=""
  188.    for nn in code:
  189.     if nn=="n":
  190.      ran=random.randint(0,9)
  191.      finish=finish+string.digits[ran]
  192.     if nn=="u":
  193.      ran=random.randint(0,25)
  194.      finish=finish+string.ascii_uppercase[ran]
  195.     if nn=="c":
  196.      ran=random.randint(0,25)
  197.      finish=finish+string.ascii_lowercase[ran]
  198.     if nn=="l":
  199.      ran=random.randint(0,31)
  200.      finish=finish+string.punctuation[ran]
  201.     if nn=="p":
  202.      ran=random.randint(0,len(c)-1)
  203.      finish=finish+c[ran]
  204.     if nn=="s":
  205.      finish=finish+b
  206.    print(finish)
  207.  except ZeroDivisionError:
  208.   input("Inserire il codice in formato corretto")
  209. while True:
  210.  input("INVIO per continuare")
  211.  print("\n"*1000)
  212.  def startfunc():
  213.   import glob
  214.   zzz=""
  215.   if zzz=="":
  216.    print("Se si vuole utilizzare un dizionario:")
  217.    print("Inserite nella cartella di questo script un file")
  218.    print("con estensione txt contenente il dizionario")
  219.    print("ogni parola deve essere separata col medesimo separatore")
  220.    print("1 = Utilizzare un dizionario")
  221.    print("2 = Creare password casuali")
  222.    print("3 = Creare password non casuali")
  223.    
  224.    while zzz!="1" and zzz!="2" and zzz!="3":
  225.     zzz=input("Scegliere che tipo di password utilizzare: ")
  226.     zzz.upper()
  227.   import os
  228.   if zzz=="2":
  229.    no()
  230.   if not(os.path.exists("dic.txt")) and zzz!="1":
  231.    clsdir()
  232.    psw()
  233.   if zzz=="3":
  234.    algos()  
  235.  startfunc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement