Is there a best practice way to store username and password on the iPhone? I am looking for something that is obviously secure but will also keep the info between app updates.
+10
A:
Use the Apple Keychain.
+ (NSString *) getPasswordForUsername: (NSString *) username andServiceName: (NSString *) serviceName error: (NSError **) error;
+ (void) storeUsername: (NSString *) username andPassword: (NSString *) password forServiceName: (NSString *) serviceName updateExisting: (BOOL) updateExisting error: (NSError **) error;
The first method allows you to request the password associated with an existing username for a particular service name (I’ve just been using the name of my app as a service name). The second allows you to store a username/password/service name combo, and allows you to specify whether or not the appropriate keychain item should be updated with the provided password if an existing one is found that matches the username and service name pair. The last parameter of each is a reference to an NSError object which will contain lower level error information if something goes wrong (and be nil if it does not).
For more information see his blog
Ghommey
2009-10-08 14:11:37
is the password returned in plaintext?
pxl
2009-10-08 18:25:31
when I add that class to my project I get a bunch of weird errors such as "_kSecAttrAccount", referenced from: _kSecAttrAccount$non_lazy_ptr in SFHFKeychainUtils.o"_SecItemDelete", referenced from: +[SFHFKeychainUtils deleteItemForUsername:andServiceName:error:] in SFHFKeychainUtils.o"_kSecReturnAttributes", referenced from: _kSecReturnAttributes$non_lazy_ptr in SFHFKeychainUtils.o"_kSecClass", referenced from: _kSecClass$non_lazy_ptr in SFHFKeychainUtils.o"_kSecClassGenericPassword", referenced from: _kSecClassGenericPassword$non_lazy_ptr in SFHFKeychainUtils.o
Jason
2009-10-12 14:31:31
That link is for the Mac OS X keychain. Here's the link for the iPhone version (they're slightly different): http://developer.apple.com/IPhone/library/documentation/Security/Conceptual/keychainServConcepts/02concepts/concepts.html
Dave DeLong
2009-10-08 14:21:27