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

时间:2022-10-11 20:08:39

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.

是否有在iPhone上存储用户名和密码的最佳实践方法?我正在寻找一些明显安全的东西,但也会保留应用更新之间的信息。

4 个解决方案

#1


19  

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

有关更多信息,请参阅他的博客

#2


5  

The keychain is what you are looking for.

钥匙扣就是你要找的。

#3


3  

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

使用Keychain,这里有一些代码可以让它变得非常简单。适用于设备和模拟器。

#4


2  

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

请参阅通用钥匙串示例源。这是去恕我直言的方式

#1


19  

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

有关更多信息,请参阅他的博客

#2


5  

The keychain is what you are looking for.

钥匙扣就是你要找的。

#3


3  

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

使用Keychain,这里有一些代码可以让它变得非常简单。适用于设备和模拟器。

#4


2  

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

请参阅通用钥匙串示例源。这是去恕我直言的方式