import string as st
import secrets as sc
all_ = ''.join([i for i in st.printable if not i in st.whitespace])
def result(chars,length):
return ''.join(sc.choice(chars) for _ in range(length))
print(result(all_,int(input('длина пароля '))))
from random import choice
# Constants for character sets
DIGITS = "0123456789"
VOWEL_LOWERCASE = "aeiouy"
VOWEL_UPPERCASE = "AEIOUY"
CONSONANT_LOWERCASE = "bcdfghjklmnpqrstvwxz"
CONSONANT_UPPERCASE = "BCDFGHJKLMNPQRSTVWXZ"
PUNCTUATION = "#$&@_"
# Function to validate the input pattern
def validate_pattern(pattern):
valid_chars = VOWEL_LOWERCASE + VOWEL_UPPERCASE + CONSONANT_LOWERCASE + CONSONANT_UPPERCASE + DIGITS + PUNCTUATION
if all(char in valid_chars for char in pattern):
return True
return False
# Function to generate a password based on a given template
def generate_password(template):
password = ""
for char in template:
if char in CONSONANT_LOWERCASE:
password += choice(CONSONANT_LOWERCASE)
elif char in CONSONANT_UPPERCASE:
password += choice(CONSONANT_UPPERCASE)
elif char in VOWEL_LOWERCASE:
password += choice(VOWEL_LOWERCASE)
elif char in VOWEL_UPPERCASE:
password += choice(VOWEL_UPPERCASE)
elif char in DIGITS:
password += choice(DIGITS)
elif char in PUNCTUATION:
password += choice(PUNCTUATION)
else:
password += char # If it's an unsupported character, keep it as is
return password
# Main function to run the password generator
def main():
list_passwords = set() # Use a set to avoid duplicates
while True:
sample_password = input("Введите шаблон для генерации пароля: ")
if validate_pattern(sample_password):
break
else:
print("\nВ вашем шаблоне должны быть только английские буквы, цифры или специальные символы (#$&@_).")
# Generate passwords until we reach the desired count
desired_count = 10 # You can change this to any number you want
while len(list_passwords) < desired_count:
new_password = generate_password(sample_password)
list_passwords.add(new_password)
print(f"\nСгенерированные пароли ({len(list_passwords)}):")
print(*list_passwords, sep="\n")
if __name__ == "__main__":
main()
import string, random
p = ""
for I in range(10):
p += random.choice(string.ascii_letters)
print(p)