在 iPhone 上存储用户名和密码的最佳做法是什么? [英] What is the best practice to store username and password on the iPhone?

查看:33
本文介绍了在 iPhone 上存储用户名和密码的最佳做法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

解决方案

使用 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;

<块引用>

第一种方法允许你请求与某个关联的密码特定的现有用户名服务名称(我刚刚使用我的应用程序的名称作为服务名称).这第二个允许您存储一个用户名/密码/服务名称组合,并允许您指定是否不是合适的钥匙串项目应使用提供的更新如果找到现有的密码匹配用户名和服务名称对.每个的最后一个参数是对 NSError 对象的引用这将包含较低级别的错误出现问题时的信息(如果不是,则为 nil).

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

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.

解决方案

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

这篇关于在 iPhone 上存储用户名和密码的最佳做法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆