#Community Practice Problem (Regex)

Write a python program using regex to identify whether the entered password is valid or not.
Criteria for a valid password:

  1. It should contain atleast one uppercase letter
  2. It should contain atleast one lowercase letter
  3. It should be more than 8 characters long.
  4. It should contain atleast one digit.
  5. It should contain atleast one special character.
2 Likes

import re
passwd=input(‘enter the password’)
pattern=‘\d’
match=re.findall(pattern,passwd)
if len(passwd)>=8:
print(‘valid passwd’)
else:
print(‘invalid passwd’)

3 Likes

password = input(“please enter a password”)
for strlen.password>8:
pattern= (‘\s+’)
validpassword=(pattern,string)
if validpassword:
print(“valid”)
else:
print(“invalid”)

3 Likes

Great work everyone! @rudolphreganjoseph.n @nagmafariyal2017 :grin:

1 Like

import re
password= input(“Enter password”)
pattern1= ‘\d+’
result = re.findall(pattern1,password)
pattern2= ‘\W+’
result2 = re.findall(pattern2,password)

if len(password) >= 8:
print (“password lenth is acceptable”)

if result:
print(“valid password”)

else:
print(“invalid password.please use atleaset 1 numeric”)
if result2:
print (“valid”)
else:
print(“does not contain alpha character”)
else:
print (“invalid. password minimum 8 character length”)

1 Like