Skip to content

Instantly share code, notes, and snippets.

@valllllll2000
Last active July 24, 2023 13:31
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save valllllll2000/f1d0fa4f36a3e3413aa015cc1f08426b to your computer and use it in GitHub Desktop.
Save valllllll2000/f1d0fa4f36a3e3413aa015cc1f08426b to your computer and use it in GitHub Desktop.
random password
import secrets
import string
letters = string.ascii_letters
digits = string.digits
special_chars = string.punctuation
alphabet = letters + digits + special_chars
pwd_length = 16
pwd = ''
for i in range(pwd_length):
pwd += ''.join(secrets.choice(alphabet))
print(pwd)
while True:
pwd = ''
for i in range(pwd_length):
pwd += ''.join(secrets.choice(alphabet))
if (any(char in special_chars for char in pwd) and
sum(char in digits for char in pwd)>=2):
break
print(pwd)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment