What is the best practice to store username and password on the iPhone?

末鹿安然 提交于 2019-12-18 11:56:15

问题


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.


回答1:


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




回答2:


The keychain is what you are looking for.




回答3:


Use the Keychain, here is some code to make it very easy. Works on the device and simulator.




回答4:


See the Generic Keychain example source. That's the way to go IMHO



来源:https://stackoverflow.com/questions/1538031/what-is-the-best-practice-to-store-username-and-password-on-the-iphone

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!