TLP - Programming Maintenance
Week 2 - A function to determine password strength
Background
We have all had to work with websites with different rules about what counts as a valid password. I have even used several that offer up a "score" to tell you how good your password is. Have you ever wondered what a website uses when they tell you that your password is weak or strong? This function will use one simple technique to calculate a password strength score and category.
Task
- Produce a function called passwordStrength()
- The function should take in one string as a parameter. This is assumed to be a potential password.
- In our function, lets produce a strength score that depends on:
- Length - one point per character
- Variability - one additional point each for each category contained in the password:
- lower-case letters
- upper-case letters
- digits
- special character
- Return a string consisting of
- The password score (using the formula above)
- followed by a space
- followed by one of four categories
- weak (scores of 10 and below)
- okay (scores of 11-12)
- good (scores of 13-15)
- strong: (scores over 15).
- Here are some samples:
Hints
- Think about this from the point of view that you will get either 0 or 1 point for having a lower case letter in your password (no or yes). You will have 0 or 1 point for having an upper case letter in your password.
- For example, "password" (the first example above) is worth 9 points because
- there are 8 letters (8 points)
- there ARE lower case letters (1 more point)
- there are NOT upper case letters (0 more points)
- there are NOT digits (0 more points)
- there are NOT special characters (0 more points)
- For example, "password" (the first example above) is worth 9 points because
- The most common mistake that I see on this assignment is that the student counts how many lower case letters there are (8) and adds 8 more points rather than 1.
- This is one of those activities where the "in" operator comes in handy.
- I strongly suggest you look for lower, upper, and digits and then assume that EVERYTHING else is a special character.