Advertisement
Guest User

Untitled

a guest
Nov 30th, 2018
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.39 KB | None | 0 0
  1. import sys
  2. import random
  3.  
  4. helpMessage = "Arguments needed: <Lowest number> <Highest number> <Special characters (true/false)>" #"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."
  5.  
  6. low = ""
  7. high = ""
  8. special_chars = ""
  9.  
  10. args = sys.argv[1:]
  11. if(len(args) == 0):
  12. sys.stdout.write("What's the lowest number for the range?\n")
  13. low = input()
  14.  
  15. sys.stdout.write("What's the highest number for the range?\n")
  16. high = input()
  17.  
  18. sys.stdout.write("Allow special characters (such as !@#$) [true/false]\n")
  19. special_chars = input()
  20. elif(len(args) == 3):
  21. try:
  22. low = args[0]
  23. high = args[1]
  24.  
  25. special_chars = args[2]
  26. except IndexError:
  27. print("\nInvalid arguments. "+helpMessage)
  28. sys.exit(0)
  29. else:
  30. print("\nInvalid argument. "+helpMessage)
  31.  
  32. try:
  33. low = int(low)
  34. high = int(high)
  35.  
  36. if(low > high):
  37. print("\nThe lowest number is higher than the highest number?? wat??")
  38. sys.exit(0)
  39.  
  40. if(special_chars.lower() == "true"): # kill me
  41. special_chars = bool(True)
  42. else: # anything else but true we'll just let the user slide with
  43. special_chars = bool(False)
  44. except ValueError:
  45. print("\nFailed to parse arguments. "+helpMessage)
  46. sys.exit(0)
  47.  
  48. length = random.randint(low, high)
  49. characters = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789")
  50.  
  51. if(special_chars):
  52. newchars = list("!@#$%^&*:<>?")
  53. for character in newchars:
  54. characters.append(character)
  55.  
  56. password = ""
  57.  
  58. charAmount = 0
  59. while charAmount < length: # gen the password
  60. password += random.choice(characters)
  61. charAmount += 1
  62.  
  63. print("\n"+password)
  64.  
  65.  
  66. # ARE YOU READY KIDS!?!? THIS IS WHERE THE CODE BECOME WORSE! I KNOW, YOU THOUGHT IT WAS IMPOSSIBLE.
  67. savePassword = ""
  68.  
  69. def savePasswordFile():
  70. # sys.stdout.write("\nWhat website is this account for? (The name not domain)\n")
  71. # account = input().lower()
  72.  
  73. sys.stdout.write("\nWhat do you want this file to be named?\n")
  74. fileName = input().lower()
  75.  
  76. sys.stdout.write("\nWhat is the username/email address for the account?\n")
  77. username = input().lower()
  78.  
  79. passwordFile = open(fileName+".txt", "w")
  80. # 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")
  81. passwordFile.writelines("Username: "+username+"\n")
  82. passwordFile.writelines("Password: "+password)
  83. passwordFile.close()
  84.  
  85. print("\nPassword saved!")
  86.  
  87. sys.exit(0)
  88. def askToSave(repeat):
  89. sys.stdout.write("\nWould you like to save this password? (y/n)\n")
  90. if(repeat == True):
  91. savePassword = input().lower()
  92.  
  93. 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
  94. savePasswordFile()
  95. elif(savePassword == "n"):
  96. sys.exit(0)
  97. else:
  98. print("Invalid choice!")
  99. askToSave(True)
  100.  
  101. askToSave(False)
  102.  
  103. savePassword = input().lower()
  104.  
  105. if(savePassword == "y"):
  106. savePasswordFile()
  107. elif(savePassword == "n"):
  108. print("\nExiting...")
  109. sys.exit(0)
  110. else:
  111. print("\nInvalid choice!")
  112. askToSave(True)
  113.  
  114. sys.exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement