Password Validator Python and Java
We already have a Post on Generating Random Password which will generate strong random password for you.But Still if you want to have your own Password and want to check if it is Strong or not.For that we are going to create our Password Validator in python and java.
Conditions for A strong Password:
- Their should be atleast one Upper Case Letter.
- Atleast 2 numbers and 2 Special Characters.
- Their should be atleast one Lower Case Letter.
- Length of the Password Should be greater than 8 or atleast 8.
- Whitespace should not be their.
So without further discussion lets dive into the coding part:
Password Validator Code in Java
Password Validator Code Python:
def isValid(password):
digitcount = 0
specialcount = 0
uppercase = False
lowercase = False
whitespace = False
if len(password) >= 8:
for i in range(len(password)):
if password[i].isupper():
uppercase = True
elif password[i].islower():
lowercase = True
elif password[i].isdigit():
digitcount += 1
elif password[i] == " ":
whitespace = True
else:
specialcount += 1
if uppercase and lowercase and not whitespace and digitcount >= 2 and specialcount >=2:
return "Valid Password"
elif not uppercase:
return "Upper case Letter is needed"
elif not lowercase:
return "Lower case Letter is needed"
elif whitespace:
return "White space is not allowed"
elif digitcount < 2:
return "Atleast 2 numbers are needed"
else:
return "Atleast 2 special characters are needed"
else:
return "Length should be atleast 8"
password = input("Enter password :\n")
print(isValid(password))
Related posts:
Conclusion:
Thus We have Created our own Password Validator in python and java.
Please Let me Know, If you have any doubts.
Please Let me Know, If you have any doubts.