NSUserDefaults or keychain is better to save username and password in iPhone app

Johnykutty picture Johnykutty · Sep 21, 2012 · Viewed 12.3k times · Source

In my iphone app there is some confidential data like username, password and some urls to a webservice. Which one is better NSUserdefaults or keychain. Somebody says NSUserdefaults is insecure. Why it is insecure? and can any one give the pros and cons of each one.

Answer

Apple_iOS0304 picture Apple_iOS0304 · Sep 21, 2012

NSUserDefaults is quite easy to use and stores one value per key only. But apparently, it is not a very secure method, as there is no encryption.

But the Keychain is secure, though it is a bit hard to code. You can refer these link to use keychain access.

http://log.scifihifi.com/post/55837387/simple-iphone-keychain-code

you can also use this library deviced by Simon

https://github.com/goosoftware/GSKeychain

I hope it helps you!!