
- Practice Built-In Methods and Functions
- Practice Loops
- Practice Custom Functions
Build a Password Checker
In this lesson, weβre going to build a password checker logic with python.

We'll create logic similar to any sign-up page where it tells you that your password is weak... We all hate it, but it's a good excercise in Python.
So, Hereβs the plan:
πββοΈ Ask for username and password
βοΈ At least 8+ characters
βοΈ Check for lowercase letter
βοΈ Check for uppercase letter
βοΈ Check for digits
βοΈ Check for symbols
βοΈ Check for spaces
π Report if password is secure enough.

Same as previously - Pause here and try to do it on your own (without ChatGPT). Then come back and let's do it together.
Ready? Set. Code π
πββοΈ Ask User Input
The first step is simple: ask the user for their username and password.

π Security Checks
Now, we need to make a series of checks.
For clarity, we'll create placeholders for each check to hold True/False values so we can print the results later on too.
Now our goal is to go one by one and set it to True if it passes the test. I'll combine it into a single snippet so it's easier to read:
As you can see it's very simple to do checks, we just need to remember a few built-in methods or membership operators to create these tests.
Also notice that we're creating a loop for a string, because it's a sequence of characters, and we can look at each character until we satisfy a condition.
Step 3: Combining the Checks
Lastly, we need to create a logical statement if everything is good or notify the user what's wrong. That's why we created variables to hold True/False about each test earlier.
We could use AND operator to combine all tests:
But there are too many of them and it looks ugly.
So instead, we can combine them into a list and then use all() built-in function to check if all values are True. It will look much cleaner and easier to read.
π‘ Try To Always Make Your Code More Readable!
Notify What's Wrong:
Lastly, If the password isnβt strong enough, the user should know why. Let's look at each check variable and display the message if it's False. And avoid elif in this case, because we want to make individual checks unrelated to each tother.
Now the feedback is clear.
Wrapping It in a Function
Lastly, let's turn everything into a function and add doc-strings to describe our code:
Also notice that I've added return statements if password is secure or not.
Test Multiple Password
Now that our code is wrapped into a function we can reuse it multiple times. So let's create a list of passwords to check, and then test them one by one by calling the function name.
This will check each password one by one, giving clear feedback on how to make it more secure.

Final Thoughts
And thatβs it! π
Now you know how to create a Password Checker with Python.
No password can escape your security check now:

Safe, Safe, Safe, DETECTED...π
Happy Coding!
πββοΈ See you in the next lesson.
- EF
Follow along the lesson and create password checker.
β Then you can add another function to check usernames:
- At least 4 characters
- No Spaces
- Exclude Curse Words
- Add More Custom Rules β¨
β¨οΈ Happy Coding!
