Last active
July 24, 2023 13:31
-
-
Save valllllll2000/f1d0fa4f36a3e3413aa015cc1f08426b to your computer and use it in GitHub Desktop.
random password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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