Advertisement
maynul67

Random Password with at least one uppercase,one lowercase,one digit and one special char

Jul 20th, 2021
1,554
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.70 KB | None | 0 0
  1. import random
  2. import string
  3. all_letters = string.ascii_letters
  4. all_uppercase = string.ascii_uppercase
  5. all_lowercase = string.ascii_lowercase
  6. all_numbers = string.digits
  7. all_special = string.punctuation
  8. all = all_letters+all_numbers+all_special
  9.  
  10. n = int(input("How many characters in your password?   "))
  11.  
  12. #ensuring all requirements are fullfilled first
  13. password = " "
  14. password += random.choice(all_lowercase)
  15. password += random.choice(all_uppercase)
  16. password += random.choice(all_numbers)
  17. password += random.choice(all_special)
  18.  
  19. #filling the remaining characters by substracting 4 from n
  20. for char in range(0,n-4):
  21.     char = random.choice(all)
  22.    
  23.     password = password + char
  24.    
  25.  
  26. print("your random password is :", password)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement