i'd like to suggest change the order of authentication from "Online, then offline key" to "Offline key, then online".
your current method has one weak spot. if network connection is present but internet unavailable - trainer hangs up. you can fix it by setting up an timeout for online authentication - 30-90 seconds would be enough. if trainer could not reach your server in that period then try to find offline key.