2

Password validation in Python

 1 year ago
source link: https://www.geeksforgeeks.org/videos/password-validation-in-python/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

Password validation in Python

Password validation in Python
Hey everyone. Welcome to Geeks
  • 50 Views
  • 24/08/2022

In this video, we will write a python program to validate a password.

We have discussed 2 approaches:

  1. Naive Approach
  2. Using Regex

We will follow some common validation logic as follows:

Password should:

  1. Have at least one number
  2. Have at least one lowercase and one uppercase alphabet
  3. Have at least one special symbol
  4. Be between 6-20 characters long.

Method 1: Naive approach: In this method, we iterate on each character of the password string. We compare the character for if it's a special character or digit or upper/lower case letter. In each case, we increment the count of the particular category by 1.
At the end of the iteration if any of the category count is 0, we declare the password as invalid, otherwise print password is valid.

Method 2: Using Regex: In this method, we have used Python's re module and findall() method to find a list of characters of a particular category. Each category is matched for a specific pattern (for example, digits are [0-9]). If all the category match returns non-empty list, we print the password as valid, else we print the password as invalid.

Password validation in Python
https://www.geeksforgeeks.org/password-validation-in-python/


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK