What is the best way to maintain the login credentials in iOS?

Arun picture Arun · Nov 20, 2012 · Viewed 9.4k times · Source

I need to maintain my log-in credential for throughout the app so, I have 3 options to maintain my log-in credentials...

1 key chain
2 NSUserDefaults
3 plist

Which one is best one to choose ? Is there any other way is there to store the log-in credentials?

Thanks in advance

Answer

Midhun MP picture Midhun MP · Nov 20, 2012

I'll suggest keychain for storing the login credentials due to the security feature it provides. The keychain services on iOS provide a means to securely store content such as passwords, keys, certificates, etc.

Sensitive data like passwords and keys should be stored in the Keychain. Apple's Keychain Services Programming Guide states that

"A keychain is an encrypted container that holds passwords for multiple applications and secure services. Keychains are secure storage containers, which means that when the keychain is locked, no one can access its protected contents".

Here is two nice tutorial for you.

  1. How Not to Store Passwords in iOS
  2. Using Keychain to Store Username and Password
  3. How to secure user data