Password protect iPhone app
Asked Answered
D

4

11

I'm starting a new app, and I'd like to know how to require a password to open it.

I was considering a UIActionSheet in the application didFinishLaunchingWithOptions method of the app delegate implementation file, but am unsure how to go about doing so. I'm going to keep trying though.

Found this video, which seems pretty helpeful.

Now I've got my UIActionSheet to pop up displaying "Enter password," and am trying to figure how to add a keypad to the action sheet.

Diabolize answered 23/5, 2010 at 8:55 Comment(3)
I thought something that would help people with the same problem should go in community wiki. Am I mistaken? I apologize if so.Diabolize
You should ask for a mod to delete this and make another question without community wiki.Holster
This answer is also pretty useful https://mcmap.net/q/1014292/-xcode-display-login-view-in-applicationdidbecomeactiveCoheir
B
8

I think you may have better luck using a full UIViewController instance instead of a UIActionSheet. Adding keyboard behavior to an action sheet will be difficult if not impossible.

If you create a UIViewController subclass, you can make your application delegate present it in -application:didFinishLaunchingWithOptions:. Assuming you're using some sort of UIViewController or UINaviagtionController for your main interface, you could have the password view controller presented modally at startup using UIViewController-presentModalViewController:animated:.

Once you have your password view controller, you'll need to add a UITextField for password entry. Make the text field become firstResponder (by calling becomeFirstResponder on it), and that will cause the keyboard to be displayed. You may also want to set the keyboardAppearance property on the text field to control how the keypad appears if for example you want to limit to a numeric PIN versus a full password. Setting the secureTextEntry property may also be desirable to prevent the actual password from being display. See the UITextInputTraits protocol on UITextField for both of those options.

In order to make the app secure, you would create your password view controller so that it has no buttons or navigation options other than a "Submit" or "Login" type button. If the user enters the correct password, you dismiss the modal view controller and let them in. If they don't know the password, their only choice is to tap the Home button to exit your application as they'd have no way to proceed beyond the modal view controller.

Burin answered 23/5, 2010 at 8:55 Comment(3)
Thanks! That makes sense reading it. I haven't had a chance to try it out yet though. I appreciate your help!Diabolize
Implementing UIKeyInput Protocol Reference would also be a good idea so you can zeroize the password from the underlying data store. Zeroization is usually required by bodies NIST, DoD (STIGs), CIS (Security Benchmarks), etc.Angle
@surlac Couple of options. For maximum security, store it in the app's Keychain. For reasonable security, store a hash of it in the app's NSUserDefaults and compare the hash of what they enter to what you have stored. Then there's no way to recover their actual PIN, but you can still verify it. Google about a bit, and you can find SHA1 hash implementations for iOS that use the built in CommonCrypto libraries.Burin
B
8

I think you may have better luck using a full UIViewController instance instead of a UIActionSheet. Adding keyboard behavior to an action sheet will be difficult if not impossible.

If you create a UIViewController subclass, you can make your application delegate present it in -application:didFinishLaunchingWithOptions:. Assuming you're using some sort of UIViewController or UINaviagtionController for your main interface, you could have the password view controller presented modally at startup using UIViewController-presentModalViewController:animated:.

Once you have your password view controller, you'll need to add a UITextField for password entry. Make the text field become firstResponder (by calling becomeFirstResponder on it), and that will cause the keyboard to be displayed. You may also want to set the keyboardAppearance property on the text field to control how the keypad appears if for example you want to limit to a numeric PIN versus a full password. Setting the secureTextEntry property may also be desirable to prevent the actual password from being display. See the UITextInputTraits protocol on UITextField for both of those options.

In order to make the app secure, you would create your password view controller so that it has no buttons or navigation options other than a "Submit" or "Login" type button. If the user enters the correct password, you dismiss the modal view controller and let them in. If they don't know the password, their only choice is to tap the Home button to exit your application as they'd have no way to proceed beyond the modal view controller.

Burin answered 23/5, 2010 at 8:55 Comment(3)
Thanks! That makes sense reading it. I haven't had a chance to try it out yet though. I appreciate your help!Diabolize
Implementing UIKeyInput Protocol Reference would also be a good idea so you can zeroize the password from the underlying data store. Zeroization is usually required by bodies NIST, DoD (STIGs), CIS (Security Benchmarks), etc.Angle
@surlac Couple of options. For maximum security, store it in the app's Keychain. For reasonable security, store a hash of it in the app's NSUserDefaults and compare the hash of what they enter to what you have stored. Then there's no way to recover their actual PIN, but you can still verify it. Google about a bit, and you can find SHA1 hash implementations for iOS that use the built in CommonCrypto libraries.Burin
A
3

Thought the repo http://github.com/lashad/PTPasscodeViewController could be useful for someone visit this page.

Aleta answered 23/5, 2010 at 8:55 Comment(0)
F
1

What about a UIAlertView? But I don't know if the app gets rejected or not. A few say yes, the other no. Doesn't know if things changed in the past.

Here are some links:

http://junecloud.com/journal/code/displaying-a-password-or-text-entry-prompt-on-the-iphone.html

UITextField in UIAlertView on iPhone - how to make it responsive?

http://iphone-dev-tips.alterplay.com/2009/12/username-and-password-uitextfields-in.html

http://discussions.apple.com/thread.jspa?threadID=1674641&start=15&tstart=0

http://icodeblog.com/2009/11/09/iphone-coding-tutorial-inserting-a-uitextfield-in-a-uialertview/

Most of the links do the same, they all use CGAffineTransformMakeTranslation. Someone stated that this isn't needed for iOS 4. And sometimes there are problems. Didn't tried it out, because I don't want to get rejected ...

Fagot answered 23/5, 2010 at 8:55 Comment(1)
Thanks! I haven't had much time to work on this app any more, but when I pick it back up I'll be sure to check out your advice. Thanks!Diabolize

© 2022 - 2024 — McMap. All rights reserved.