Last active
May 22, 2019 10:34
-
-
Save yashshah1/a7e0053bda154a8298212b250bbc5e3e to your computer and use it in GitHub Desktop.
Password validtor
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import re | |
""" | |
A website requires the users to input username and password to register. | |
Write a program to check the validity of password input by users. | |
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 | |
Your program should accept a sequence of comma separated passwords and will check them according to the above criteria. | |
Passwords that match the criteria are to be printed, each separated by a comma. | |
Example: If the following passwords are given as input to the program: | |
ABd1234@1,a F1#,2w3E*,2We3345 | |
Then, the output of the program should be: | |
ABd1234@1 | |
""" | |
passwords = input().strip().split(',') | |
regex_pattern = "^(?=.*[a-z])(?=.*\d)(?=.*[A-Z])(?=.*[@$#])[A-Za-z\d@$#]{6,12}$" | |
regex_pattern = re.compile(regex_pattern) | |
valid_passwords = [] | |
for i in passwords: | |
if re.match(regex_pattern, i): | |
valid_passwords.append(i) | |
print(" ".join(valid_passwords)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment