Advertisement
UF6

password_generator

UF6
Nov 15th, 2023
801
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.83 KB | Source Code | 0 0
  1. import random
  2. import string
  3.  
  4. def generate_password(length=12):
  5.     characters = string.ascii_letters + string.digits + string.punctuation
  6.     password = ''.join(random.choice(characters) for _ in range(length))
  7.     return password
  8.  
  9. def main():
  10.     print("Welcome to the Password Generator!")
  11.     while True:
  12.         try:
  13.             password_length = int(input("Enter the desired password length (at least 4 characters): "))
  14.             if password_length < 4:
  15.                 print("Password length should be at least 4 characters.")
  16.                 continue
  17.             password = generate_password(password_length)
  18.             print("Generated password:", password)
  19.             break
  20.         except ValueError:
  21.             print("Please enter a valid number for the password length.")
  22.  
  23. if __name__ == "__main__":
  24.     main()
  25.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement