Question
In python: write a function that checks whether a string is a valid password, suppose the password rules are as follows: -A password must have
In python: write a function that checks whether a string is a valid password, suppose the password rules are as follows:
-A password must have at least eight characters.
-A password must consist of only letters and digits.
A password must contain at least two digits
Have the program:
Begin the program and each function with a comment.
Define a function to prompt the user for a password and return it to main( ).
Define a second function to check the password and return True if it is valid, else False. Call this from main( ), also.
Run your program with test cases demonstrating valid passwords and each of the following error cases, with appropriate error messages.
Show multiple error messages for multiple infractions. See 5th test case below.
Use local variables, rather than global.
Use structured code (e.g., no unstructured exits from loops).
Test Cases:
1) abcd1234 is valid.
2) Password must be at least 8 characters long.
abcd123 is invalid.
3) Password must have at least 2 digits.
abcdefg8 is invalid.
4) Password must be alphanumeric.
abcd123* is invalid.
5) Password must be at least 8 characters long.
Password must have at least 2 digits.
Password must be alphanumeric.
abc3* is invalid.
Hints: use the following to help write the program
-len( )
- isalnum( )
- isdigit( ) can also be used for characters
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started