Three lines of code max, in any language.
Not a computer expert, that sounds fairly simple. I think the same should apply to Soc Security - if you leave the country beyond x amount of days - say after 180 days, no access.