Back to Freecodecamp

Step 22

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

latest1.2 KB
Original Source

--description--

It seems all fine, but it would be nice to have a way to check that the generated password complies to specific features. For example, a minimum number of special characters, digits, or uppercase/lowercase letters. You are going to take care of that very soon.

For now, comment out the last two lines of your code.

--hints--

You should turn the last two lines of your code into comments.

js
({ test: () => {
  assert.match(code, /#\s*new_password\s*=\s*generate_password\s*\(\s*8\s*\)/);
  assert.match(code, /#\s*print\s*\(\s*new_password\s*\)/);
} })

--seed--

--seed-contents--

py
import secrets
import string


def generate_password(length):
    # 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
    
--fcc-editable-region--
new_password = generate_password(8)
print(new_password)
--fcc-editable-region--