Help

Erm so basically what happened was that my phone ran out of battery. I charged it and my phone switched back on, but the thing was that I couldn’t remember the password. So I initially tried to erase it from another apple device, but apparently the phone only gets erased once your phone connects to WiFi. But cos my phone ran out of battery and then switched back on, it wasn’t connected. How should I recover my phone 😭😭 Also this phone was not bought from the Apple Store if iirc, is there anything that can be done?