Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import sys
- import random
- 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."
- low = ""
- high = ""
- special_chars = ""
- args = sys.argv[1:]
- if(len(args) == 0):
- sys.stdout.write("What's the lowest number for the range?\n")
- low = input()
- sys.stdout.write("What's the highest number for the range?\n")
- high = input()
- sys.stdout.write("Allow special characters (such as !@#$) [true/false]\n")
- special_chars = input()
- elif(len(args) == 3):
- try:
- low = args[0]
- high = args[1]
- special_chars = args[2]
- except IndexError:
- print("\nInvalid arguments. "+helpMessage)
- sys.exit(0)
- else:
- print("\nInvalid argument. "+helpMessage)
- try:
- low = int(low)
- high = int(high)
- if(low > high):
- print("\nThe lowest number is higher than the highest number?? wat??")
- sys.exit(0)
- if(special_chars.lower() == "true"): # kill me
- special_chars = bool(True)
- else: # anything else but true we'll just let the user slide with
- special_chars = bool(False)
- except ValueError:
- print("\nFailed to parse arguments. "+helpMessage)
- sys.exit(0)
- length = random.randint(low, high)
- characters = list("abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ123456789")
- if(special_chars):
- newchars = list("!@#$%^&*:<>?")
- for character in newchars:
- characters.append(character)
- password = ""
- charAmount = 0
- while charAmount < length: # gen the password
- password += random.choice(characters)
- charAmount += 1
- print("\n"+password)
- # ARE YOU READY KIDS!?!? THIS IS WHERE THE CODE BECOME WORSE! I KNOW, YOU THOUGHT IT WAS IMPOSSIBLE.
- savePassword = ""
- def savePasswordFile():
- # sys.stdout.write("\nWhat website is this account for? (The name not domain)\n")
- # account = input().lower()
- sys.stdout.write("\nWhat do you want this file to be named?\n")
- fileName = input().lower()
- sys.stdout.write("\nWhat is the username/email address for the account?\n")
- username = input().lower()
- passwordFile = open(fileName+".txt", "w")
- # 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")
- passwordFile.writelines("Username: "+username+"\n")
- passwordFile.writelines("Password: "+password)
- passwordFile.close()
- print("\nPassword saved!")
- sys.exit(0)
- def askToSave(repeat):
- sys.stdout.write("\nWould you like to save this password? (y/n)\n")
- if(repeat == True):
- savePassword = input().lower()
- 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
- savePasswordFile()
- elif(savePassword == "n"):
- sys.exit(0)
- else:
- print("Invalid choice!")
- askToSave(True)
- askToSave(False)
- savePassword = input().lower()
- if(savePassword == "y"):
- savePasswordFile()
- elif(savePassword == "n"):
- print("\nExiting...")
- sys.exit(0)
- else:
- print("\nInvalid choice!")
- askToSave(True)
- sys.exit(0)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement