Skip to content

Instantly share code, notes, and snippets.

@renatocfrancisco
Last active January 13, 2023 14:56
Show Gist options
  • Save renatocfrancisco/02f6fa0d670d44a6276711a117719ab4 to your computer and use it in GitHub Desktop.
Save renatocfrancisco/02f6fa0d670d44a6276711a117719ab4 to your computer and use it in GitHub Desktop.
Random Password Generator in Python
import string
import random
def main():
password_length = int(input("Length (int) of password? "))
punctuation_option = input("Punctuation on password? (y/n)")
if(punctuation_option == 'y'):
characters = list(string.ascii_letters + string.digits + string.punctuation)
else:
characters = list(string.ascii_letters + string.digits)
random.shuffle(characters)
generate(password_length, characters)
def generate(password_length, characters):
password = []
for x in range(password_length):
password.append(random.choice(characters))
random.shuffle(password)
print("".join(password))
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment