![]() |
VOOZH | about |
Creating a strong password is one of the simplest yet most important steps for keeping accounts secure. A valid password usually contains mix of uppercase and lowercase letters, at least one number, at least one special symbol, a length that’s neither too short nor too long etc.
In this article, we will explore three different methods to check whether a given password meets these rules.
For this example, a valid password must:
Input: Geek12#
Output: Password is valid.
Input: asd123
Output: Invalid Password.
Let's explore different methods to do this:
We can use a single regular expression to check all password rules at once like length, uppercase, lowercase, digits and special symbols making the validation compact and efficient.
Password is valid.
Explanation:
This approach checks all password rules in a single loop by using ord() to get each character’s ASCII value. It efficiently identifies digits, uppercase letters, lowercase letters and special symbols without multiple any() calls.
True True Password should have at least one of the symbols $@#% False
Explanation:
This method uses simple built-in string functions like .isdigit(), .isupper() and .islower() to manually check each password rule. It’s straightforward to understand but requires multiple separate checks for each condition.
Password is valid
Explanation:
Related Articles: