viligen

password_validator

Dec 5th, 2021
612
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. password = input()
  2.  
  3. while True:
  4.     command = input().split()
  5.     if command[0] == "Complete":
  6.         break
  7.     elif command[0] == "Validation":
  8.  
  9.         if len(password) < 8:
  10.             print("Password must be at least 8 characters long!")
  11.         for ch in password:
  12.             if not ch.isalnum() and ch != "_":
  13.                 print("Password must consist only of letters, digits and _!")
  14.                 break
  15.         if len([s for s in password if s.isupper()]) == 0:
  16.             print("Password must consist at least one uppercase letter!")
  17.         if len([s for s in password if s.islower()]) == 0:
  18.             print("Password must consist at least one lowercase letter!")
  19.         if len([s for s in password if s.isdigit()]) == 0:
  20.             print("Password must consist at least one digit!")
  21.     elif command[1] == "Upper":
  22.         idx = int(command[2])
  23.         if 0 <= idx < len(password):
  24.             password = password[:idx] + password[idx].upper() + password[idx+1:]
  25.             print(password)
  26.     elif command[1] == "Lower":
  27.         idx = int(command[2])
  28.         if 0 <= idx < len(password):
  29.             password = password[:idx] + password[idx].lower() + password[idx+1:]
  30.             print(password)
  31.     elif command[0] == "Insert":
  32.         idx = int(command[1])
  33.         char = command[2]
  34.         if 0 <= idx < len(password):
  35.             password = password[:idx] + char + password[idx:]
  36.             print(password)
  37.     elif command[0] == "Replace":
  38.         char = command[1]
  39.         value = int(command[2])
  40.         new_char = chr(ord(char) + value)
  41.         if char in password:
  42.             password = password.replace(char, new_char)
  43.             print(password)
  44.  
  45.  
  46.  
RAW Paste Data