In this program, we will be taking a password as a combination of alphanumeric characters along with special characters, and check whether the password is valid or not with the help of few conditions.
Primary conditions for password validation :
- Minimum 8 characters.
- The alphabets must be between [a-z]
- At least one alphabet should be of Upper Case [A-Z]
- At least 1 number or digit between [0-9].
- At least 1 character from [ _ or @ or $ ].
Input : R@m@_f0rtu9e$ Output : Valid Password Input : Rama_fortune$ Output : Invalid Password Explanation: Number is missing Input : Rama#fortu9e Output : Invalid Password Explanation: Must consist from _ or @ or $
Here we have used the re module that provide support for regular expressions in Python. Along with this the re.search() method returns False (if the first parameter is not found in the second parameter) This method is best suited for testing a regular expression more than extracting data. We have used the re.search() to check the validation of alphabets, digits or special characters. To check for white spaces we use the “\s” which comes in the module of the regular expression.
Attention geek! Strengthen your foundations with the Python Programming Foundation Course and learn the basics.
To begin with, your interview preparations Enhance your Data Structures concepts with the Python DS Course.
- Dunn index and DB index - Cluster Validity indices | Set 1
- Python Program to generate one-time password (OTP)
- getpass() and getuser() in Python (Password without echo)
- Python | Random Password Generator using Tkinter
- Password validation in Python
- Python | Prompt for Password at Runtime and Termination with Error Message
- Generating Strong Password using Python
- Categorize Password as Strong or Weak using Regex in Python
- EasyGUI – Password Box
- EasyGUI – Multi Password Box
- Python program to check if the list contains three consecutive common numbers in Python
- Python program to check if a string is palindrome or not
- Python List Equality | Program to check if two given matrices are identical
- Python program to check if string is empty or not
- Python program to check if given string is pangram
- Python program to check if a given string is Keyword or not
- Python program to check if number is palindrome (one-liner)
- Python program to check if given value occurs atleast k times
- Python program to check whether the string is Symmetrical or Palindrome
- Python program to check if the given string is IPv4 or IPv6 or Invalid
Improved By : Divyu_Pandey