Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Python program to check the validity of a Password?
Here given a password, our task is to check that this Password is valid or not. Here we use re module that provide regular expression and re.search() is used for checking the validation of alphabets, digits or special characters.
Algorithm
Step 1: first we take an alphanumeric string as a password. Step 2: first check that this string should minimum 8 characters. Step 3: the alphabets must be between a-z. Step 4: At least one alphabet should be in Uppercase A-Z. Step 5: At least 1 number or digit between 0-9. Step 6: At least 1 character from [_ or @ or $].
Example Code
# Python program to check valid password
import re
passw = input("Enter Password ::>")
fl = 0
while True:
if (len(passw)<8):
fl= -1
break
elif not re.search("[a-z]", passw):
fl = -1
break
elif not re.search("[A-Z]", passw):
fl = -1
break
elif not re.search("[0-9]", passw):
fl = -1
break
elif not re.search("[_@$]", passw):
fl = -1
break
elif re.search("\s", passw):
fl = -1
break
else:
fl = 0
print(" This Is Valid Password")
break
if fl ==-1:
print("Not a Valid Password")
Output
Enter Password ::> vbnA@hj9 This Is Valid Password
Advertisements