Question:
Write a program to check the validity of password input by users.
Accept a sequence of comma separated passwords and check them according to the above criteria. Print the valid passwords
Program:
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 |
import re value = [] items=[x for x in raw_input("Enter passwords separated by commas for checking validity.Press Enter to end.\n").split(',')] for p in items: if len(p)<6 or len(p)>12: continue else: pass if not re.search("[a-z]",p): continue elif not re.search("[0-9]",p): continue elif not re.search("[A-Z]",p): continue elif not re.search("[$#@]",p): continue elif re.search("\s",p): continue else: pass value.append(p) print "Valid passwords",value |
Following are the criteria for checking the password:
1. At least 1 letter between [a-z]
2. At least 1 number between [0-9]
3. At least 1 letter between [A-Z]
4. At least 1 character from [$#@]
5. Minimum length of transaction password: 6
6. Maximum length of transaction password: 12
Output:
1 2 3 4 5 |
Enter passwords separated by commas for checking validity.Press Enter to end globalsqa,#GlobalSQA2 Valid passwords ['#GlobalSQA2'] |
Leave a Reply