First of all we need to determine the model phone. I hope it is a personal security lock code you are referring to here, where you don't know the password. One thing about passwords; write it down first, before entering it in whatever device you plan to use. That goes for online pages too. (Unlocking a phone is a totally different story, but not as difficult as a lot of people may think. The reason being, there are reputable online unlocking services available for all. The fees are quite reasonable. I use two of them quite often.)
Now if it is a Blackberry, then you may have to lose your data in the process of wiping it clean and setting up your new password when the phone reboots. If you have a Sony Ericsson you will need to use the Omnius for SE software. First you need to join the GSMCure Forum at www.omnius-server.com
(free) and use the download link provided in there to download Omnius for SE. If you have a Samsung, then the Omnius for SAM will have to be downloaded and installed. The use of the software to find the security code on your phone is a paid service.
If you have any of the other Android phones, then you will have to manually backup the data on your phone by using the appropriate desktop manager or PC suite or PC companion. It's always wise to check out the appropriate forums for your phone first, before doing a master reset. I have deliberately not gone into detail here as the topic is quite broad. There is a lot more information on Google.com. I hope this helps to point you in the right direction.