There is a very good chance that you may forget the password of the Samsung Galaxy S2 if you have just changed it and you have assign a new passcode.
If you happen to lock yourself out of your own phone, then there is a couple of things you could try to get back access to your device.
Unlock with a code
1. Switch off your Samsung Galaxy S2.
2. Next remove the SIM card from the device.
3. Now switch the phone back on.
4. Then put in the code *2767*28787#.
5. You will see the phone will turn off and on again.
At this point you should be able to get back into your SGS2. If not then try the below reset method.
1. Go to the Home screen.
2. Go to Settings.
3. Select Privacy.
4. Select Factory Data reset.
5. Select Reset Phone.
6. Select Erase Everything.
You devices should be resetting now.
Hardware Key Reset
1. Switch off the phone. Remove the battery and put it back in if you device is not responding.
2. Now press and hold down the volume up + volume down button. Then press and release the Home/Power button.
3. When you see a menu, select Clear Storage.
4. Then confirm if you want to go ahead.
After the reset you should be able to get back into your SGS2 device.