Tell us what’s happening:
Describe your issue in detail here.
Your code so far
import re
import secrets
import string
# User Editable Region
def generate_password(length = "16", nums = "1", special_chars = "1", uppercase = "1", lowercase = "1"):
pass
# User Editable Region
# Define the possible characters for the password
letters = string.ascii_letters
digits = string.digits
symbols = string.punctuation
# Combine all characters
all_characters = letters + digits + symbols
while True:
password = ''
# Generate password
for _ in range(length):
password += secrets.choice(all_characters)
constraints = [
(nums, r'\d'),
(special_chars, fr'[{symbols}]'),
(uppercase, r'[A-Z]'),
(lowercase, r'[a-z]')
]
# Check constraints
if all(
constraint <= len(re.findall(pattern, password))
for constraint, pattern in constraints
):
break
return password
new_password = generate_password(nums=1, length=8, special_chars=1, uppercase=1, lowercase=1)
print(new_password)
Your browser information:
User Agent is: Mozilla/5.0 (Macintosh; Intel Mac OS X 10_15_7) AppleWebKit/605.1.15 (KHTML, like Gecko) Version/17.2.1 Safari/605.1.15
Challenge Information:
Learn Regular Expressions by Building a Password Generator - Step 68