Created
April 5, 2022 15:03
-
-
Save mka142/553267243161da338456990e1a9ec69c to your computer and use it in GitHub Desktop.
Generate password in python using letters, numbers and punctation
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import random | |
def password_generator(length=50,table=[1,1,0]): # to refactor | |
IS_CHOOSEEN = lambda x,y: x if y==1 else '' | |
LETTERS = IS_CHOOSEEN(string.ascii_letters,table[0]) | |
NUMBERS = IS_CHOOSEEN(string.digits,table[1]) | |
PUNCTUATION = IS_CHOOSEEN(string.punctuation,table[2]) | |
# create alphanumerical by fetching string constant | |
printable = NUMBERS + LETTERS + PUNCTUATION | |
# convert printable from string to list and shuffle | |
printable = list(printable) | |
random.shuffle(printable) | |
# generate random password | |
random_password = random.choices(printable, k=length) | |
# convert generated password to string | |
random_password = ''.join(random_password) | |
return random_password |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment