Nokia has posted the following instructions for doing a factory reset at boot time, it should also work for HTC and Samsung Windows Phone 8 devices in addition to Nokia Lumia devices.
[Warning: This erases all personal content on your phone and restores the factory settings.]
1. Make sure the charger is disconnected, and switch the phone off.
2. Press and hold the volume down key, and connect the charger. The screen shows an exclamation mark (!).
3. Press the keys in the following order: volume up, volume down, power, and volume down. Your phone resets, and boots up. This may take several minutes.
For step #2, you can substitute plugging the charger, by pressing the power button for a few seconds, while pressing the volume down key. You want to keep the volume down pressed until the exclamation mark comes up on the screen.