Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- import random
- import string
- # checking the input
- while True:
- pass_len = input("Please enter a whole number equal to 8 or higher: ")
- try:
- if int(pass_len) >= 8:
- pass_len = int(pass_len)
- break
- except ValueError:
- print("Invalid input.")
- symbols_categories = [string.digits]
- # defining complexity
- pass_type = input("Do you want the password to have capital letters? (y/n): ")
- if pass_type in "YesyesYy":
- symbols_categories.append(string.ascii_uppercase)
- pass_type = input("Do you want the password to have lower letters? (y/n): ")
- if pass_type in "YesyesYy":
- symbols_categories.append(string.ascii_lowercase)
- pass_type = input("Do you want the password to have symbols? (y/n): ")
- if pass_type in "YesyesYy":
- symbols_categories.append(string.punctuation)
- number_of_symbols = pass_len // len(symbols_categories)
- number_of_remains = pass_len % len(symbols_categories)
- generated_password = str()
- final_pass = str()
- # minimum symbols of each category
- for _ in range(number_of_symbols):
- for n in range(len(symbols_categories)):
- generated_password += random.choice(symbols_categories[n])
- # adding random symbols of random category to fill the password
- for _ in range(number_of_remains):
- category = random.choice(symbols_categories)
- generated_password += random.choice(category)
- # shuffling the password
- for i in range(pass_len):
- symbol = random.choice(generated_password)
- generated_password = generated_password.replace(symbol, "", 1)
- final_pass += symbol
- if len(symbols_categories) >=3:
- print('Here is your very secure password: ')
- elif 3> len(symbols_categories) >= 2:
- print('Here is your pretty secure password: ')
- elif len(symbols_categories) = 1:
- print('Here is your basic password: ')
- print(final_pass)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement