def getPassword():
  while True: 
    password = input("Enter the password: ")
    if password == "12345": break 
    print("INVALID. ", end = "")
# getPassword ends here

# main program starts here  
getPassword()
...do stuff...