How to choose account and service values for SSKeychain

5.9k views Asked by At

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?

1

There are 1 answers

0
Suhail Patel On BEST ANSWER

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.

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 is so easy and fantastic to use. Definitely a good choice!