简体   繁体   English

在iPhone上存储用户名和密码的最佳做法是什么?

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

Is there a best practice way to store username and password on the iPhone? 是否有在iPhone上存储用户名和密码的最佳实践方法? I am looking for something that is obviously secure but will also keep the info between app updates. 我正在寻找一些明显安全的东西,但也会保留应用更新之间的信息。

Use the Apple Keychain. 使用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). 每个参数都是对NSError对象的引用,如果出现错误,它将包含较低级别的错误信息(如果不存在则为nil)。

For more information see his blog 有关更多信息,请参阅他的博客

钥匙扣是您正在寻找的。

Use the Keychain, here is some code to make it very easy. 使用Keychain,这里有一些代码可以让它变得非常简单。 Works on the device and simulator. 适用于设备和模拟器。

See the Generic Keychain example source. 请参阅通用钥匙串示例源。 That's the way to go IMHO 这是去恕我直言的方式

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM