Advertisement
Dar954826

New Password[ENG].py

Feb 1st, 2015
166
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 5.85 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("Have not used any dictionary")
  11.    no()
  12.   while lll!="Y" and lll!="N" and lll!="y" and lll!="n":
  13.    lll=input("Use "+g[ggg]+" as dictionary?[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("Insert separator words: [n = head]")
  26.   try:
  27.    if b=="":
  28.     6/0
  29.   except ZeroDivisionError:
  30.    b=input("You must enter a separator, if there leave type ENTER without typing anything: ")
  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("Enter numbers?[Y/N]")
  43.    set1=set1.upper()
  44.   while set2!="n" and set2!="N" and set2!="Y" and set2!="y":
  45.    set2=input("Enter lowercase?[Y/N]")
  46.    set2=set2.upper()
  47.   while set3!="n" and set3!="N" and set3!="Y" and set3!="y":
  48.    set3=input("Enter uppercase?[Y/N]")
  49.    set3=set3.upper()
  50.   while set4!="n" and set4!="N" and set4!="Y" and set4!="y":
  51.    set4=input("Insert special characters?[Y/N]")
  52.    set4=set4.upper()
  53.   try:
  54.    set5=int(input("Enter password length: "))
  55.   except ValueError:
  56.    set5=4
  57.   try:
  58.    set6=int(input("Enter password to generate: "))
  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("This dictionary can not be used")
  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("This dictionary can not be used")
  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("Use this dictionary?[Y/N] ")
  112.   if b=="y"or b=="Y":
  113.    try:
  114.     k=int(input("Insert number words: "))
  115.     if k<0:
  116.      6/0
  117.    except ValueError:
  118.     k=1
  119.    except ZeroDivisionError:
  120.     k=1
  121.    kk=input("Insert separator words: ")
  122.    kkk=int(input("Insert number 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("Click to continue")
  139.  print("\n"*1000)
  140. def algos():
  141.  try:
  142.   import os,random,string
  143.   a=b=c=d=var=code=finish=""
  144.   e=f=0
  145.   dic=[]
  146.   print("n = Number")
  147.   print("u = Uppercase")
  148.   print("c = Lowercase")
  149.   print("l = Special")
  150.   print("p = Personal")
  151.   print("s = Separator")
  152.   print("Enter the number of characters")
  153.   print("Example code: 2n3c")
  154.   print("It will generate passwords with 2 numbers and 3 lowercase")
  155.   a=input("Insert code: ")
  156.   a=a.lower()
  157.   error="abdefghijkmoqrtvwxyz"
  158.   for err in error:
  159.    if a.count(err)!=0:
  160.     6/0
  161.    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:
  162.     6/0
  163.   if a.count("s")!=0:
  164.    b=input("Insert separator: ")
  165.   if a.count("p")!=0:
  166.    c=input("Insert personal characters: ")
  167.   d=input("Insert number of password: ")
  168.   if d=="":
  169.    d="1"
  170.   while True:
  171.    if e==len(a):
  172.     break
  173.    else:
  174.     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":
  175.      var=var+a[e]
  176.     else:
  177.      try:
  178.       code=code+(a[e]*int(var))
  179.      except ValueError:
  180.       code=code+(a[e]*1)
  181.      var=""
  182.     e=e+1
  183.   for kk in range(int(d)):
  184.    finish=""
  185.    for nn in code:
  186.     if nn=="n":
  187.      ran=random.randint(0,9)
  188.      finish=finish+string.digits[ran]
  189.     if nn=="u":
  190.      ran=random.randint(0,25)
  191.      finish=finish+string.ascii_uppercase[ran]
  192.     if nn=="c":
  193.      ran=random.randint(0,25)
  194.      finish=finish+string.ascii_lowercase[ran]
  195.     if nn=="l":
  196.      ran=random.randint(0,31)
  197.      finish=finish+string.punctuation[ran]
  198.     if nn=="p":
  199.      ran=random.randint(0,len(c)-1)
  200.      finish=finish+c[ran]
  201.     if nn=="s":
  202.      finish=finish+b
  203.    print(finish)
  204.  except ZeroDivisionError:
  205.    print("Insert the code in correct format")
  206. while True:
  207.  input("ENTER to continue")
  208.  print("\n"*1000)
  209.  def startfunc():
  210.   import glob
  211.   zzz=""
  212.   if zzz=="":
  213.    print("If you want to use a dictionary:")
  214.    print("Place a file in the folder of this script")
  215.    print("with extension .txt containing the dictionary")
  216.    print("every word must be separated with the same separator")
  217.    print("1 = Use a dictionary")
  218.    print("2 = Create a random password")
  219.    print("3 = Create a not random password")
  220.    while zzz!="1" and zzz!="2" and zzz!="3":
  221.     zzz=input("Choose what kind of password use: ")
  222.     zzz.upper()
  223.   if zzz=="2":
  224.    no()
  225.   import os
  226.   if not(os.path.exists("dic.txt")) and  zzz!="1":
  227.    clsdir()
  228.    psw()
  229.   if zzz=="3":
  230.    algos()
  231.  startfunc()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement