You could use WiFi.hasCredentials() to check if there are any stored credentials and most likely one of the five possible sets should usually work.
But if you really could not WiFi connect, you can always use a serial terminal or CLI to provide new credentials.
You need to be aware that the WiFi credentials are stored in flash without good wear leveling, so if you keep clearing and setting credentials e.g. in loop() you might wear out your flash, rendering your device unusable.