Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

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.

like image 780
Johnykutty Avatar asked Sep 21 '12 06:09

Johnykutty


People also ask

How do I store credentials in iOS app?

You can simply use NSURLCredential , it will save both username and password in the keychain in just two lines of code.

Is NSUserDefaults secure?

Because NSUserDefaults stores all data in an unencrypted . plist file, a curious person could potentially view this data with minimal effort. That means that you should never store any type of sensitive data inside NSUserDefaults.

What is the difference between keychain and Userdefaults?

A keychain is an encrypted container that holds passwords for multiple applications and secure services. Apple Inc. uses keychains as password management system in Mac OS and iOS. NSUserDefaults Provides a way for application behavior customization based on user preferences.

What is NSUserDefaults?

The NSUserDefaults class provides a programmatic interface for interacting with the defaults system. The defaults system allows an app to customize its behavior to match a user's preferences. For example, you can allow users to specify their preferred units of measurement or media playback speed.


1 Answers

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!!

like image 115
Apple_iOS0304 Avatar answered Sep 18 '22 14:09

Apple_iOS0304