By default, iPhone doesn’t require you to enter a passcode to unlock it.
Set a passcode: Go to Settings > General > Passcode Lock and set a 4-digit passcode. To increase security, turn off Simple Passcode and use a longer passcode.
If you forget your passcode, you must restore the iPhone software. See Updating and restoring iPhone software.
Allow access when iPhone is locked: Go to Settings > General > Passcode Lock. You can use the following without unlocking iPhone:
Siri (See Setting options for Siri.)
Voice Dial (This setting is available only when Siri is turned off.)
Reply with Message (See Receiving calls.)
Passbook (See Passbook.)
Erase data after ten failed passcode attempts: Go to Settings > General > Passcode Lock and tap Erase Data. After ten failed passcode attempts, all settings are reset, and all your information and media are erased by removing the encryption key to the data (which is encrypted using 256-bit AES encryption).