问题描述
我正在考虑使用在iOS应用中存储密码,但我不确定是否需要帐户和服务的某些特定值,或者只有任意值才可以。有没有常见的做法?
I'm thinking of using SSKeychain for storing a password in an iOS app, but I'm not sure if I need some specific value for the account and service, or if it will be OK with just arbitrary ones. Is there a common practice?
推荐答案
服务应该是您应用的唯一字符串,可能使用iOS捆绑标识符作为服务或应用程序或Web应用程序的名称/ URL或您为其设置密码的任何内容。理想情况下,这应该在整个应用程序中保持不变,但没有特别的偏好。我个人更喜欢将其设置为Web服务URL,但这是我的首选。
The Service should be a unique string for your App, possibly use the iOS Bundle Identifier as the Service or the name/URL of your Application or Web App or whatever you are setting the Password for. This should ideally be constant throughout your Application but there is no specific preference. I personally prefer to set it to the Web Service URL but that is my preference.
帐户位实质上类似于任何应用程序上的用户名字段。这样,您可以为同一服务存储多个密码,但不同的帐户。如果您正在处理没有用户名字段的应用程序,那么您可以将其设置为用户或任意内容,但在整个应用程序和将来的版本中保持不变。
The account bit is in essence similar to a Username field on any application. That's so you can store multiple passwords for the same service but for different accounts. If you are working on an application which doesn't have a username field then you could set it to 'user' or something arbitrary but remains constant throughout the application and in future versions.
因此,如果我为acme.com服务存储joebloggs的密码和密码'test',我将按照以下方式存储:
So if I am storing the password for joebloggs with password 'test' for the acme.com service, here is how I'd store it:
NSString *password = [SSKeychain setPassword:@"test" forService:@"acme.com" account:@"joebloggs"];
SSKeychain 非常简单易用。绝对是个不错的选择!
SSKeychain is so easy and fantastic to use. Definitely a good choice!
这篇关于如何为SSKeychain选择帐户和服务值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!