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
- The data is persistent even after app uninstall-install
- 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.
- The data is removed only on Device Reset from settings.