Advertisement
Dar954826

Password[ITA].py

Jan 15th, 2015
183
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.99 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.   pas=set1=set2=set3=set4=set5=log=""
  41.   while set1!="n" and set1!="N" and set1!="Y" and set1!="y":
  42.    set1=input("Inserire numeri?[Y/N]")
  43.    set1=set1.upper()
  44.   while set2!="n" and set2!="N" and set2!="Y" and set2!="y":
  45.    set2=input("Inserire lettere minuscole?[Y/N]")
  46.    set2=set2.upper()
  47.   while set3!="n" and set3!="N" and set3!="Y" and set3!="y":
  48.    set3=input("Inserire maiuscole?[Y/N]")
  49.    set3=set3.upper()
  50.   while set4!="n" and set4!="N" and set4!="Y" and set4!="y":
  51.    set4=input("Inserire caratteri speciali?[Y/N]")
  52.    set4=set4.upper()
  53.   try:
  54.    set5=int(input("Inserire lunghezza password: "))
  55.   except ValueError:
  56.    set5=4
  57.   try:
  58.    set6=int(input("Inserire password da generare: "))
  59.   except ValueError:
  60.    set6=1
  61.   if set1=="N" and set2=="N" and set3=="N" and set4=="N" :
  62.    set1="Y"
  63.   for j in range(set6):
  64.    while len(pas)!=set5:
  65.     rndset=random.randint(1,4)
  66.     if rndset==1 and set1=="Y":
  67.      log=random.randint(1,10)
  68.      log=string.digits[log-1]
  69.     if rndset==2 and set2=="Y":
  70.      log=random.randint(1,26)
  71.      log=string.ascii_lowercase[log-1]
  72.     if rndset==3 and set3=="Y":
  73.      log=random.randint(1,26)
  74.      log=string.ascii_uppercase[log-1]
  75.     if rndset==4 and set4=="Y":
  76.      log=random.randint(1,32)
  77.      log=string.punctuation[log-1]
  78.     pas=pas+log
  79.     log=""
  80.    print(pas)
  81.    pas=""
  82. def psw():
  83.  
  84.  import random,os,string
  85.  b=n=""
  86.  z=[]
  87.  if os.path.exists("dic.txt"):
  88.   try:
  89.    a=open("dic.txt","r")
  90.   except MemoryError:
  91.    import random
  92.    gdkj=random.randint(0,9999999999)
  93.    gdkj="dic"+str(gdkj)+".txt"
  94.    print("Questo dizionario non può essere utilizzato")
  95.    os.rename("dic.txt",gdkj)
  96.    b="N"
  97.   cache=a.read()
  98.   cache=cache.split("|")
  99.   if len(cache)==1:
  100.    a.close()
  101.    try:
  102.     6/0
  103.    except ZeroDivisionError:
  104.     import random
  105.     gdkj=random.randint(0,9999999999)
  106.     gdkj="dic"+str(gdkj)+".txt"
  107.     print("Questo dizionario non può essere utilizzato")
  108.     os.rename("dic.txt",gdkj)
  109.     b="N"
  110.   while b!="Y" and b!="n" and b!="N" and b!="y" and b!=00:
  111.    b=input("Utilizzare questo dizionario?[Y/N] ")
  112.   if b=="y"or b=="Y":
  113.    try:
  114.     k=int(input("Inserire numero parole: "))
  115.     if k<0:
  116.      6/0
  117.    except ValueError:
  118.     k=1
  119.    except ZeroDivisionError:
  120.     k=1
  121.    kk=input("Inserire separatore parole: ")
  122.    kkk=int(input("Inserire numero password: "))
  123.    for tm in range(kkk):
  124.     for m in range(k):
  125.      b=random.randint(1,len(cache))
  126.      b=cache[b-1]
  127.      if n!="":
  128.       n=n+kk+b
  129.      else:
  130.       n=n+b
  131.     print(n)
  132.     n=""
  133.     #---------------
  134.   else:
  135.    no()
  136.  else:
  137.   no()
  138.  input("Clicca per continuare")
  139.  print("\n"*1000)
  140. while True:
  141.  def startfunc():
  142.   import glob
  143.   zzz=""
  144.   if zzz=="":
  145.    print("Se si vuole utilizzare un dizionario:")
  146.    print("Inserite nella cartella di questo script un file")
  147.    print("con estensione txt contenente il dizionario")
  148.    print("ogni parola deve essere separata col medesimo separatore")
  149.    while zzz!="Y" and zzz!="N" and zzz!="y" and zzz!="n":
  150.     zzz=input("Utilizzare un dizionario?[Y/N]")
  151.     zzz.upper()
  152.   import os
  153.   if not(os.path.exists("dic.txt")) and zzz!="Y":
  154.    pass
  155.   clsdir()
  156.   psw()
  157.  startfunc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement