Advertisement
George_Ivanov05

0.6

Jul 5th, 2021
136
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 1.23 KB | None | 0 0
  1. def is_password_length_valid(password: str):
  2.     if 6 <= len(password) <= 10:
  3.         return True
  4.     return False
  5.  
  6.  
  7. def is_password_alphanumeric(password: str):
  8.     return password.isalnum()  # new function # returns boolean
  9.  
  10.     #is_alphanum = True
  11.     #for ch in password:
  12.         #if not ch.isalpha() or ch.isdigit():
  13.             #is_alphanum = False
  14.             #break
  15.     #return is_alphanum
  16.  
  17.  
  18. def does_password_have_at_least_two_digits(password: str):
  19.     digits_count = 0
  20.  
  21.     for ch in password:
  22.         if ch.isdigit():
  23.             digits_count += 1
  24.     if digits_count >= 2:
  25.         return True
  26.     else:
  27.         return False
  28.  
  29. def validate_password(password):
  30.     is_valid = True
  31.  
  32.     if not is_password_length_valid(password):
  33.         print("Password must be between 6 and 10 characters")
  34.         is_valid = False
  35.     if not is_password_alphanumeric(password):
  36.         print("Password must consist only of letters and digits")
  37.         is_valid = False
  38.     if not does_password_have_at_least_two_digits(password):
  39.         print(f"Password must have at least 2 digits")
  40.         is_valid = False
  41.  
  42.     if is_valid:
  43.         print("Password is valid")
  44.  
  45. password_input = input()
  46.  
  47. validate_password(password_input)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement