ComeçarComece de graça

Building a password validator

Your team is developing an authentication system for a website. To ensure user accounts are secure, you need to create a validate_password() function that checks if passwords meet minimum security requirements. The function should verify that a password is at least eight characters long and contains at least one special character from the string module's punctuation collection.

The string module and a test password variable user_password are already imported for you.

Este exercício faz parte do curso

Python intermediário para desenvolvedores

Ver curso

Instruções do exercício

  • Complete the validate_password() function to check if the password is at least 8 characters long.
  • Add a loop to check if any character in the password exists in string.punctuation.
  • Call the function with user_password, and store the result in is_valid.

Exercício interativo prático

Experimente este exercício completando este código de exemplo.

def validate_password(password):
    # Check if password is at least 8 characters long
    if ____(____) >= 8:
        # Check if password contains a special character
        for char in password:
            if char in string.____:
                return True
    return False

# Call the function and store the result
is_valid = ____(____)
print("Is the password valid? ", is_valid)
Editar e executar o código