daily pastebin goal
64%
SHARE
TWEET

Untitled

a guest Jan 24th, 2019 76 Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. # passcodeGenerator.py
  2. # Program that generates random PLAINTEXT passwords
  3.  
  4. import random
  5. import string
  6. import os
  7.  
  8. def main():
  9.     print("\nCreates random passwords based on user input\n")
  10.  
  11.  
  12.     # Get user input (amounts, symbols yes/no, min length, max length)
  13.     passcode_amount = int(input("How many passcodes should be generated? "))
  14.     p_symbol = str(input("Can punctuation and special characters be used (Y/N)? "))
  15.     if p_symbol == "y" or p_symbol == "Y":
  16.         p_symbol = string.punctuation
  17.     else:
  18.         p_symbol = ""        
  19.     p_min_char = int(input("Minimum number of characters? "))
  20.     p_max_char = int(input("Maximum number of characters? "))
  21.     if p_max_char < p_min_char:
  22.         p_min_char, p_max_char = p_max_char, p_min_char
  23.  
  24.  
  25.     # Create a file for the PLAINTEXT passwords and write to it
  26.     filename = "passcode"  
  27.     while os.path.isfile(filename + ".txt") == True: # Adds _new to the name if file exists
  28.         filename += "_new"
  29.     filename += ".txt"
  30.     f = open(filename, "w")
  31.  
  32.  
  33.     # Generate passwords using the random and string modules, and writes it as PLAINTEXT to the file
  34.     for i in range (passcode_amount):
  35.         p_mixer = "".join(random.choices(string.ascii_uppercase + string.ascii_lowercase + string.digits + p_symbol, k=random.randint(p_min_char, p_max_char)))
  36.         f.write(p_mixer + "\n")
  37.  
  38.  
  39.     # Save the file and open it for the user
  40.     print("Generated", passcode_amount, "combinations.\nSaved as:", os.getcwd() + "\\" + filename)
  41.     f.close()
  42.     os.startfile(os.getcwd() + "\\" + filename)
  43.  
  44.    
  45.     run_again = str(input("Run again (Y/N)? "))
  46.     if run_again == "Y" or run_again == "y":
  47.         main()
  48.        
  49.  
  50. if __name__ == "__main__":
  51.     main()
RAW Paste Data
We use cookies for various purposes including analytics. By continuing to use Pastebin, you agree to our use of cookies as described in the Cookies Policy. OK, I Understand
Pastebin PRO 'WINTER SPECIAL'!
Get 40% OFF Pastebin PRO accounts!
 
Top