Advertisement
b_gandurov

simple_password_generator

May 20th, 2022 (edited)
190
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.82 KB | None | 0 0
  1. import random
  2. import string
  3.  
  4. # checking the input
  5. while True:
  6.     pass_len = input("Please enter a whole number equal to 8 or higher: ")
  7.     try:
  8.         if int(pass_len) >= 8:
  9.             pass_len = int(pass_len)
  10.             break
  11.     except ValueError:
  12.         print("Invalid input.")
  13.  
  14. symbols_categories = [string.digits]
  15.  
  16. # defining complexity
  17. pass_type = input("Do you want the password to have capital letters? (y/n): ")
  18. if pass_type in "YesyesYy":
  19.     symbols_categories.append(string.ascii_uppercase)
  20. pass_type = input("Do you want the password to have lower letters? (y/n): ")
  21. if pass_type in "YesyesYy":
  22.     symbols_categories.append(string.ascii_lowercase)
  23. pass_type = input("Do you want the password to have symbols? (y/n): ")
  24. if pass_type in "YesyesYy":
  25.     symbols_categories.append(string.punctuation)
  26.  
  27. number_of_symbols = pass_len // len(symbols_categories)
  28. number_of_remains = pass_len % len(symbols_categories)
  29. generated_password = str()
  30. final_pass = str()
  31.  
  32. # minimum symbols of each category
  33. for _ in range(number_of_symbols):
  34.     for n in range(len(symbols_categories)):
  35.         generated_password += random.choice(symbols_categories[n])
  36.  
  37. # adding random symbols of random category to fill the password
  38. for _ in range(number_of_remains):
  39.     category = random.choice(symbols_categories)
  40.     generated_password += random.choice(category)
  41.  
  42. # shuffling the password
  43. for i in range(pass_len):
  44.     symbol = random.choice(generated_password)
  45.     generated_password = generated_password.replace(symbol, "", 1)
  46.     final_pass += symbol
  47.  
  48. if len(symbols_categories) >=3:
  49.     print('Here is your very secure password: ')
  50. elif 3> len(symbols_categories) >= 2:
  51.     print('Here is your pretty secure password: ')
  52. elif len(symbols_categories) = 1:
  53.     print('Here is your basic password: ')
  54. print(final_pass)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement