Write a Python program to check the validity of a password


Introduction

Write a Python program to check the validity of a password.

Validation

At least 1 letter between [a-z] and 1 letter between [A-Z]

At least 1 number between [0-9]

At least 1 character from [$#@]

Minimum length 6 characters

Maximum length 16 characters

I have used python 3.7 compiler for debugging purpose.


techstudy.org

HP 15 Core i3 7th gen Laptop(4GB, 1TB HDD, Windows 10) | Rs. 31,490

  1. import re
  2. password= input("Input your password: ")
  3. x = True
  4. while x:
  5. if (len(password)<6 or len(password)>12):
  6. break
  7. elif not re.search("[a-z]",password):
  8. break
  9. elif not re.search("[0-9]",password):
  10. break
  11. elif not re.search("[A-Z]",password):
  12. break
  13. elif not re.search("[$#@]",password):
  14. break
  15. elif re.search("\s",password):
  16. break
  17. else:
  18. print("Valid Password")
  19. x=False
  20. break
  21.  
  22. if x:
  23. print("Not a Valid Password")

Result

python language techstudy.org

     





Related Topics




Popular Posts