Advertisement
GeorgiLukanov87

password validator final exam

Aug 8th, 2022
121
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Python 2.35 KB | None | 0 0
  1. password = input()
  2.  
  3. command_data = input()
  4. while not command_data == "Complete":
  5.     curr_data = command_data.split()
  6.     command = curr_data[0]
  7.     if command == "Make":
  8.  
  9.         if curr_data[1] == "Upper":
  10.             index = int(curr_data[2])
  11.             new_password = ""
  12.             for current_index, char in enumerate(password):
  13.                 if current_index == index:
  14.                     new_password += char.upper()
  15.                 else:
  16.                     new_password += char
  17.             password = new_password
  18.             print(password)
  19.  
  20.         elif curr_data[1] == "Lower":
  21.             index = int(curr_data[2])
  22.             new_password = ""
  23.             for current_index, char in enumerate(password):
  24.                 if current_index == index:
  25.                     new_password += char.lower()
  26.                 else:
  27.                     new_password += char
  28.             password = new_password
  29.             print(password)
  30.  
  31.     elif command == "Insert":
  32.         index = int(curr_data[1])
  33.         char = curr_data[2]
  34.         if index in range(len(password)):
  35.             password = password[:index] + char + password[index:]
  36.             print(password)
  37.  
  38.     elif command == "Replace":
  39.         char = curr_data[1]
  40.         value = int(curr_data[2])
  41.         if char in password:
  42.             password = password.replace(char, chr(ord(char) + value))
  43.             print(password)
  44.  
  45.     elif command == "Validation":
  46.         if len(password) < 8:
  47.             print("Password must be at least 8 characters long!")
  48.         for ch in password:
  49.             if not ch.isalnum() and not ch == "_":
  50.                 print("Password must consist only of letters, digits and _!")
  51.                 break
  52.         upper_counter = 0
  53.         lower_counter = 0
  54.         digit_counter = 0
  55.         for ch in password:
  56.             if ch.isupper():
  57.                 upper_counter += 1
  58.             elif ch.islower():
  59.                 lower_counter += 1
  60.             elif ch.isdigit():
  61.                 digit_counter += 1
  62.         if upper_counter == 0:
  63.             print("Password must consist at least one uppercase letter!")
  64.         if lower_counter == 0:
  65.             print("Password must consist at least one lowercase letter!")
  66.         if digit_counter == 0:
  67.             print("Password must consist at least one digit!")
  68.  
  69.     command_data = input()
  70.  
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement