Write a Python program to validate a password.

Password should be in a proper or a specific format to secure the application so how to validate a password in Python?

How to validate a password in Python?

Let’s accept a password as a mix of alphanumeric characters alongside exceptional characters, and check whether the password is legitimate or not with the assistance of a few conditions.

What is a password?

Input: Abcdof90@

Output: The password is valid

Algorithm to validate the password:

  •       Enter a password
  •       First, check whether the password is greater than 5 characters or not.
  •       Then check whether the first character is in uppercase or not.
  •       Having at least one lowercase character.
  •       Having at least one numeric value.
  •       Having at least one special character.

Python program to validate a password.

lower, upper, special, digit = 0, 0, 0, 0
password = input("Enter your password")
if (len(password) >= 6):
    for i in password:

        for word in password.split():
            if(word[0].isupper()):
                upper += 1

        if(i.islower()):
            lower += 1

        if(i.isdigit()):
            digit += 1

        if(i == '@' or i == '$' or i == '_' or i == '#'):
            special += 1

else:
    print("Password should be more than 6 characters")
if (lower >= 1 and upper >= 1 and special >= 1 and digit >= 1):
    print("Valid Password")
else:
    print("Invalid Password")

Output: Printing whether the password is valid or not in Python.