Advertisement
CodeCrusader

Safe Password Generator

Jun 10th, 2023
118
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.67 KB | Source Code | 0 0
  1. import random
  2. import string
  3.  
  4. def generate_password(length):
  5.     try:
  6.         length = int(length)
  7.     except ValueError:
  8.         print("Invalid input. Please enter a valid integer.")
  9.         return
  10.  
  11.     if length <= 0:
  12.         print("Password length must be a positive integer.")
  13.         return
  14.  
  15.     password_characters = string.ascii_letters + string.digits + string.punctuation
  16.     password = ''.join(random.choice(password_characters) for _ in range(length))
  17.     return password
  18.  
  19. password_length = input("Enter the desired length of the password: ")
  20.  
  21. password = generate_password(password_length)
  22. if password:
  23.     print(f"Generated Password: {password}")
  24.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement