How to Set Up a Passcode on Your iPhone
You can choose a passcode to prevent other people from unlocking your iPhone. Tap Passcode Lock. Then use the virtual keypad to enter a 4-digit code. Setting up a passcode, of course, keeps your messages, voicemail, and e-mail secure; and prevents other people from using your iPhone.
During setup, you have to enter the code a second time before it is accepted.
You can determine whether a passcode is required immediately, after 1 minute, after 5 minutes, or after 15 minutes. Shorter times are more secure, of course.
You can also change the passcode or turn it off later (unless your employer dictates otherwise), but you need to know the present passcode to apply any changes. If you forget the passcode, you have to restore the iPhone’s software.
One more security setting you’ll find in the Change Passcode section: You get to choose whether to show an SMS (text message) Preview or not to show such a Preview.