Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- # passcodeGenerator.py
- # Program that generates random PLAINTEXT passwords
- import random
- import string
- import os
- def main():
- print("\nCreates random passwords based on user input\n")
- # Get user input (amounts, symbols yes/no, min length, max length)
- passcode_amount = int(input("How many passcodes should be generated? "))
- p_symbol = str(input("Can punctuation and special characters be used (Y/N)? "))
- if p_symbol == "y" or p_symbol == "Y":
- p_symbol = string.punctuation
- else:
- p_symbol = ""
- p_min_char = int(input("Minimum number of characters? "))
- p_max_char = int(input("Maximum number of characters? "))
- if p_max_char < p_min_char:
- p_min_char, p_max_char = p_max_char, p_min_char
- # Create a file for the PLAINTEXT passwords and write to it
- filename = "passcode"
- while os.path.isfile(filename + ".txt") == True: # Adds _new to the name if file exists
- filename += "_new"
- filename += ".txt"
- f = open(filename, "w")
- # Generate passwords using the random and string modules, and writes it as PLAINTEXT to the file
- for i in range (passcode_amount):
- p_mixer = "".join(random.choices(string.ascii_uppercase + string.ascii_lowercase + string.digits + p_symbol, k=random.randint(p_min_char, p_max_char)))
- f.write(p_mixer + "\n")
- # Save the file and open it for the user
- print("Generated", passcode_amount, "combinations.\nSaved as:", os.getcwd() + "\\" + filename)
- f.close()
- os.startfile(os.getcwd() + "\\" + filename)
- run_again = str(input("Run again (Y/N)? "))
- if run_again == "Y" or run_again == "y":
- main()
- if __name__ == "__main__":
- main()
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement