24 Computer -- Computer System

ask mattrab Visit www.askmattrab.com for more academic resources.

Sample of a Password Strength Validation Program in Python

The following program is to check the strength of the input password under the given criteria using regular expression written in Python language. For more about regular expression, check https://en.wikipedia.org/wiki/Regular_expression.

The  criteria for a 'strong' password:


  • The password should contain at least 2 digits.

  • The password should contain at least 2 special characters(!@#$%^&*).

  • The password should contain at least 7 characters.


import re
k=str(input())
x=re.sub('[^!@#$%^&*]',"",k)
n=re.sub('[^0-9]',"",k)
if len(x)>=2 and len(n)>=2 and len(k)>=7:
print("strong")
else:
print('weak')

Discussions

Close Open App