LoslegenKostenlos starten

Invalid password

The second part of the website project is to write a script that validates the password entered by the user. The company also puts some rules in order to verify valid passwords:

  • It can contain lowercase a-z and uppercase letters A-Z
  • It can contain numbers
  • It can contain the symbols: *, #, $, %, !, &, .
  • It must be at least 8 characters long but not more than 20

Your colleague also gave you a list of passwords as examples to test.

The list passwords and the module re are loaded in your session. You can use print(passwords) to view them in the IPython Shell.

Diese Übung ist Teil des Kurses

<Kurs>Regular Expressions in Python</Kurs>
Kurs ansehen

Übungsanweisungen

  • Write a regular expression to check if the passwords are valid according to the description.
  • Search the elements in the passwords list to find out if they are valid passwords.
  • To print out the message indicating if it is a valid password or not, complete .format() statement.

Interaktive praktische Übung

Versuche dich an dieser Übung, indem du diesen Beispielcode vervollständigst.

# Write a regex to check if the password is valid
regex = ____"[____]____"

for example in passwords:
  	# Scan the strings to find a match
    if re.____(____, ____):
        # Complete the format method to print out the result
      	print("The password {____} is a valid password".format(pass_example=____))
    else:
      	print("The password {____} is invalid".format(pass_example=____))   
Code bearbeiten und ausführen