exDotaPro

password_validator

Feb 20th, 2020
266
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 0.97 KB | None | 0 0
  1. def length_check(password):
  2.     if not len(password) in range(6, 11):
  3.         return f'Password must be between 6 and 10 characters'
  4.  
  5.  
  6. def isalnum_check(password):
  7.     if not password.isalnum():
  8.         return f'Password must consist only of letters and digits'
  9.  
  10.  
  11. def isdigit_check(password):
  12.     digits = [char for char in password if char.isdigit()]
  13.     if not len(digits) >= 2:
  14.         return f'Password must have at least 2 digits'
  15.  
  16.  
  17. def valid_password(password):
  18.     if not length_check(password) and not isalnum_check(password) and not isdigit_check(password):
  19.         return f'Password is valid'
  20.  
  21.  
  22. def result_output(password):
  23.     if valid_password(password) is not None:
  24.         return valid_password(password)
  25.  
  26.     result = [length_check(password), isalnum_check(password), isdigit_check(password)]
  27.     output = [value for value in result if value is not None]
  28.     return '\n'.join(output)
  29.  
  30.  
  31. password_input = input()
  32.  
  33. print(result_output(password_input))
Advertisement
Add Comment
Please, Sign In to add comment