Dont formay cause it will still ask for security code* hard reset would make you loose everything on the phone..thats bad..=)
Hope you have your usb cables with you* then follow this(Ive tested this on n95 8gb* n82* 6500s) BB5 phones tested* havent tried this one with earlier models
First up* google Nemesis Service suit v 220.127.116.11 or later* download* install then run the application.(I think you can find it here in dotsis* cant upload* have no account..)
Then connect your phone in pc suite mode( use your usb cable). But dont open the pc suite.
Go to NSS then click the magnifying glass button on the top right* its the scan for new device button.
After your device is found* click the phone info button* top left area. Then click permanent memory tab at the bottom right.
Tick the button to file then click the read button on the right side next to it.
After it is done* open up the directory where you installed nss and find the pm folder* the directory should look like this:
there will be a pm file there with your phones IMEI(serial number) as the file name* open it with notepad. (ex.1234567890123456.pm)
Find this: 
// search for the whole  string and not just the number ok?//
easier if you would use the find tool with notepad* CTRL+F
You will be taken to the line with that string.
A few lines ABOVE it you will find this line:
Here is your lock code..=)
well not all of those digits* its in this format:
3 a1 3 a2 3 a3 3 a4 3 a5 0000000000000000
in the case above* the lock code would be 12345 (a1a2a3a4a5)
which is the default lock code*
write yours down and try not to forget it again..=)
close nss* then remove your phone*
change it in your settings..no need to elaborate on that..
you may be experinecing troubles like this:
even if you typed the correct code youll still be getting a code error message* Ive experienced this with my friends 6500slide* he previously inputed so many codes before he gave me his phone and I think this is the cause for it* I just inputed the correct code several times* rebooted and repeated the process* reboot again if necessary* take a few minutes nd a lot of patience and the code will be finally recognized..
hope this helps..
please feedback if you encounter problems along the way* and also if anyone has tried this on earlier models* we might learn something new.=)
link to download nss: download