Saving login credentials Xcode

I am implementing an application, the first view is the login view. it contains 3 textfields Account name, Username and password. i want to let the application to save the login information in order not to let the user write them each time he/she opens the application. And to be deleted when he/she logs out.

how to do that? and how to read/write on a file?

Thankfully yours


To Save:

    [[NSUserDefaults standardUserDefaults] setValue:AccountTxtField.text forKey:@"Account"];
    [[NSUserDefaults standardUserDefaults] setValue:UserTxtField.text forKey:@"Username"];
    [[NSUserDefaults standardUserDefaults] setValue:passwordTxtField.text forKey:@"password"];
    [[NSUserDefaults standardUserDefaults] synchronize];

To Read:

    NSString * _Account = [[NSUserDefaults standardUserDefaults] stringForKey:@"Account"];
    NSString * _UserName = [[NSUserDefaults standardUserDefaults] stringForKey:@"Username"];
    NSString * _password = [[NSUserDefaults standardUserDefaults] stringForKey:@"password"];

logOut : set all value is null.

Use key chain for storing login password. Below is the simple code

To store:

KeychainItemWrapper *keychain = 
 [[KeychainItemWrapper alloc] initWithIdentifier:@"MyAppLoginData" accessGroup:nil];
[keychain setObject:loginStr forKey:(id)kSecAttrAccount];
[keychain setObject:pwdStr forKey:(id)kSecValueData];

To query:

NSString *login = [keychain objectForKey:(id)kSecAttrAccount];
NSString *pwd = [keychain objectForKey:(id)kSecValueData];

To Delete:

[keychain resetKeychainItem];

You need to add KeychainItemWrapper.h and KeychainItemWrapper.m (here) in your project first.

Another important aspects of using keychain to store data is

  1. The data is persistent even after app uninstall-install
  2. The data can be shared across your apps (need to have same bundle seed id, read from here). Think of single sign on for all your apps.
  3. The data is removed only on Device Reset from settings.

This kind of sensitive data is usually stored in keychain. Similar question here

Check keychainServConcepts for saving required data

Check STUtils for saving Username and password securely.

U can also use NSUserDefault to save data with key as userName and remove when required.

Need Your Help

.change() conflict?

jquery jquery-ui

i have 2 changes, the live change works fine however the 2nd change for the selects does not seem to work, anyone got any idea or can these be merged together?

Does StandardTokenizer remove punctuation (in Lucene 4.1)

java lucene

Does StandardTokenizer remove punctuation (in Lucene 4.1)