Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Tutorial on sskeychain and basic auth for iPad apps?

Where can I find a good detailed tutorial using sskeychain to store and retrieve usernames and passwords and to do basic authentication in a UIWebView? Secondarily, am I on the right track as far as the methods needed to store and use authentication for a web based application? (See explanation below.)

I found a couple tutorials using different methods:

  • Interacting with keychain directly
  • Handmade keychain wrapper (sic)
  • SFHFKeychainUtils

According to recommendations from other SO questions below, sskeychain is recommended for an easier use of the keychain to store authentication parameters.

  • Cocoa interface to MacOS X Keychain
  • https://stackoverflow.com/questions/8381072/save-username-and-password-for-url-like-gmail-com-iphone

My plan is to store a username and password locally on the device in the keychain as recommended and connect over a UIWebView using basic auth to my PHP code. Is there a good step by step tutorial for xcode/Obj-C newbies on the topic of user authentication that would be recommended by experienced iOS developers?

The Apple documentation seems less than helpful. It's either pages with simple sales jargon or just head imploding descriptions of methods and parameters without many helpful examples.

Update:

I ended up just using NSUserDefaults to store the username and password locally and the AFNetworking library to do the authentication. If these are unwise I'd welcome an answer that supplies guidance on a better method.

like image 244
jjclarkson Avatar asked Dec 01 '22 22:12

jjclarkson


1 Answers

Using AFNetworking to do the authentication and calls to the server is great! But I would highly discourage you from storing credentials (username and password) in NSUserDefaults, since the contents are stored in a plist as plain text and can be read just by plugging your device to a mac. I recommend you to check these other questions and great post of a well-known case for further details on the topic.

You were right going for Keychain and using SSKeychain is easy and fast. You can find this good example on how to use SSKeychain to locally store the credentials.

// Store credentials in Keychain
[SSKeychain setPassword:@"thePassword"
             forService:@"com.yourCompany.yourApp"
                account:@"theUserName"];

// Retrieve credentials from Keychain
NSString *password = [SSKeychain passwordForService:@"com.yourCompany.yourApp"
                                            account:@"theUserName"];
like image 184
veducm Avatar answered Dec 19 '22 03:12

veducm