If you changed the security code and forgot it, only Method 2 (hardware keys) can save you.
If your phone is simply running slowly or a specific app is frozen, you might try a Soft Reset first. This is essentially just a forced reboot. On the Nokia 5310, this is done by simply removing the battery for a few seconds and reinserting it. It clears the temporary cache without deleting your personal data. If this does not solve your problem, proceed to the Hard Reset. How to Hard Reset NOKIA 5310 2020 Dual SIM