Advertisement
Guest User

Flex Taped Password Generator

a guest
Nov 29th, 2018
223
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 3.10 KB | None | 0 0
  1. # my discord is OnlyJoking#6197 go ahead and add me if you want
  2. import sys
  3. import random
  4.  
  5. args = sys.argv[1:]
  6.  
  7. helpMessage = "Please provide a low number and a high number for the length (Low number first, high number second), then say either true or false for special characters such as: $:/^#@ etc."
  8.  
  9.  
  10. low = ""
  11. high = ""
  12.  
  13. special_chars = ""
  14.  
  15. try:
  16.     low = args[0]
  17.     high = args[1]
  18.  
  19.     special_chars = args[2]
  20. except IndexError:
  21.     print("\nInvalid arguments. "+helpMessage)
  22.     sys.exit(0)
  23.  
  24. try:
  25.     low = int(low)
  26.     high = int(high)
  27.  
  28.     if(special_chars.lower() == "true"): # kill me
  29.         special_chars = bool(True)
  30.     else: # anything else but true we'll just let the user slide with
  31.         special_chars = bool(False)
  32. except ValueError:
  33.     print("\nFailed to parse arguments. "+helpMessage)
  34.     sys.exit(0)
  35.  
  36. length = random.randint(low, high)
  37. characters = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789")
  38.  
  39. if(special_chars):
  40.     characters.append("!") # why can i not just have these all in a string then list() them? like really python? i did it with the characters
  41.     characters.append("@") # like characters.append(list("!@#$%^&*:<>?")), that's it python.
  42.     characters.append("#")
  43.     characters.append("$")
  44.     characters.append("%")
  45.     characters.append("^")
  46.     characters.append("&")
  47.     characters.append("*")
  48.     characters.append(":")
  49.     characters.append("<")
  50.     characters.append(">")
  51.     characters.append("?")
  52.  
  53. password = ""
  54.  
  55. charAmount = 0
  56. while charAmount < length: # gen the password
  57.     password += random.choice(characters)
  58.     charAmount += 1
  59.    
  60. print("\n"+password)
  61.  
  62.  
  63. # ARE YOU READY KIDS!?!? THIS IS WHERE THE CODE BECOME WORSE! I KNOW, YOU THOUGHT IT WAS IMPOSSIBLE.
  64. savePassword = ""
  65.  
  66. def savePasswordFile():
  67.     sys.stdout.write("\nWhat website is this account for? (The name not domain)\n")
  68.     account = input().lower()
  69.  
  70.     sys.stdout.write("\nWhat is the username/email address for the account?\n")
  71.     username = input().lower()
  72.  
  73.     passwordFile = open(account+" ("+username+").txt", "w")
  74.     passwordFile.writelines("Hello, on the left side of the colon (this: ':') is the username/email,\nand on the right sideis the password that was generated.\n")
  75.     passwordFile.writelines(username+":"+password)
  76.     passwordFile.close()
  77.  
  78.     print("password saved!")
  79.  
  80.     sys.exit(0)
  81. def askToSave(repeat):
  82.     sys.stdout.write("\nWould you like to save this password? (y/n)\n")
  83.     if(repeat == True):
  84.         savePassword = input().lower()
  85.  
  86.         if(savePassword == "y"): # using this two times but i'm too lazy to figure out how to put it into a function, if that's even possible
  87.             savePasswordFile()
  88.         elif(savePassword == "n"):
  89.             sys.exit(0)
  90.         else:
  91.             print("Invalid choice!")
  92.             askToSave(True)
  93.  
  94. askToSave(False)
  95.  
  96. savePassword = input().lower()
  97.    
  98. if(savePassword == "y"):
  99.     savePasswordFile()
  100. elif(savePassword == "n"):
  101.     print("\nExiting...")
  102.     sys.exit(0)
  103. else:
  104.     print("\nInvalid choice!")
  105.     askToSave(True)
  106.  
  107. sys.exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement