How Secure is your password?

Access Granted?

Passwords help us to get into different accounts every day and are there to help computer systems to identify us.

Today we are going to make a system that checks if the password that is entered is secure enough using the following criteria:

  • Lowercase Letters
  • Uppercase Letters
  • Special Characters
  • Numbers
The use of Regualer Expressions (RegEx) will help us do this. Now it can be a bit complicated however I believe that you can do it!

Getting Setup!

Go to the starter project here and explore the code

The Code

The starter code has a function that checks for lowercase letters. Let's talk about this more.

Importing

import re is a special line of code that allows python to search strings of text for different kinds of characters. To use these powerful functions we need to import it first so our program knows to use it.

Checking for lowercase

The next job is make a function that checks if there are any lowercase letters within the password chosen. we use this using a clever little function called re.findall() this looks for a specific pattern and finds every occurance of that pattern and adds it to a list. If the list has data in then its size is bigger than 0. We can then use an if statement to check if the length of the list is bigger than 0. If it is we return True otherwise we return False.

Entering the password

After this function we start our program. The user can enter their own password and then it is checked for a lowercase letter using the function above it. If the function returns True then we are told that it contains a lowercase letter. Otherwise we are told it does not contain a lowercase letter.

import re

def lowercase(checkPassword):
    evidence = re.findall("[a-z]", checkPassword)
    if len(evidence) > 0:
        return True
    else:
        return False

# MAIN PROGRAM

myPassword = input("Enter a password: ")
containsLower = lowercase(myPassword)
if containsLower:
    print("The password contains a lowercase letter")
else:
    print("The password does not contain a lowercase letter")

The Task... If you choose to accept it (please accept it...)

Change the other three functions to check for uppercase letters, numbers, and special characters (e.g. £, $, %, *)

To complete this task, you need to use the same code as the lowercase function however change it slightly to fit the new need. Add to the main program to use your function.

To help you work out the special regEx patters you can use the website www.w3schools.com/python/python_regex.asp to help you.