goinaction / code

Source Code for Go In Action examples
4.11k stars 2.35k forks source link

Random password generator #124

Open bhanu1030 opened 1 year ago

bhanu1030 commented 1 year ago

import random import string

def generate_password(length):

Define the pool of characters to choose from

characters = string.ascii_letters + string.digits + string.punctuation

# Generate a password by randomly selecting characters from the pool
password = ''.join(random.choice(characters) for _ in range(length))

return password

Get the desired password length from the user

length = int(input("Enter the desired length of the password: "))

Generate and print the password

password = generate_password(length) print("Generated password:", password)

kuxsoq-6jukvy-rekFor commented 9 months ago

4ece8e0dfe2899947d6d565a9737b42107fcdec4