Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- """
- Written by: ETechSavvies [https://t.me/ETechSavvies] Apr 10,2021
- Description: Random Password Generator
- Copyright 2021 @ETechSavvies
- """
- import random, string
- def password_generator(length):
- if length < 4:
- return "Password length can't be lessthan 4"
- # This our dataset composed of letters, digits and symbols
- lower = string.ascii_lowercase
- upper = string.ascii_uppercase
- digits = string.digits
- symbols = string.punctuation
- combined_data = lower + upper + digits + symbols
- # This is to ensure that we have at least one character from each set of characters
- rand_lower = random.choice(lower)
- rand_upper = random.choice(upper)
- rand_digits = random.choice(digits)
- rand_symbols = random.choice(symbols)
- # We have 4 characters in the password now
- temp_pwd1 = list(rand_lower + rand_upper + rand_digits + rand_symbols)
- random.shuffle(temp_pwd1)
- # Fill in the rest of the characters by selecting randomly from the combined_data
- temp_pwd2 = random.sample(combined_data, length - 4)
- return "".join(temp_pwd1 + temp_pwd2)
- length = int(input("Enter the length of the password you want to generate: "))
- print(password_generator(length))
Advertisement
Add Comment
Please, Sign In to add comment