You can unlock a cellphone if you forgot the lock code by erasing the device, logging in with your user account or resetting the device. The exact method depends on the platform and the version of the operating system.
If you've forgotten the passcode for your iPhone, you must erase your device with iTunes. Connect the phone to your computer, open iTunes, and force restart your device by holding down the Sleep and Home buttons until the recovery mode launches. Wait for iTunes to back up your personal content on the computer, navigate to the Summary tab on the left, and click Restore iPhone. When you reach the set up screen on your iPhone, tap Restore from iTunes Backup, and select the most recent backup.
If using an Android device with the version 4.4 or older, enter an incorrect password five times in a row to lock the screen. Tap Forgot Password, and enter the email and the password associated with your Google account. Android versions 5.0 and up do not provide a way to recover the password. As such, you must reset your device to factory settings.
Because each Android manufacturer uses a different method to reset Android devices, you must refer to the manual of your phone to find out the exact method. For instance, you can access the system recovery tool by holding down the volume down volume up and power buttons on the Nexus 5.
If you have a Windows Phone, turn off the device, and connect a charger while holding down the volume down key. When the screen displays an exclamation mark, press volume up, volume down, power, and then volume down. It's crucial that you follow this exact order. Wait for the phone to reset on its own, and go through the initial setup.