Back to Freecodecamp

Step 23

curriculum/challenges/english/blocks/learn-regular-expressions-by-building-a-password-generator/656ef5bc5c0cd464be1df675.md

latest1.2 KB
Original Source

--description--

Next, you are going to give your function more parameters that will act as constraints for the generated password.

Modify your function declaration by adding nums, special_chars, uppercase, and lowercase in this order after the existent length parameter.

--hints--

Your function should take length, nums, special_chars, uppercase, and lowercase as the parameters. The order matters.

js
({ test: () => assert(runPython(`
    import inspect
    sig = str(inspect.signature(generate_password))
    sig == '(length, nums, special_chars, uppercase, lowercase)'
  `))
})

--seed--

--seed-contents--

py
import secrets
import string

--fcc-editable-region--
def generate_password(length):
--fcc-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

    password = ''
    # Generate password
    for _ in range(length):
        password += secrets.choice(all_characters)
        
    return password

# new_password = generate_password(8)
# print(new_password)