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 save the login information in order not to let the user write them each time they open the application. And to be deleted when they log out.
How to do that? And how to read/write on a file?
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
This kind of sensitive data is usually stored in keychain. Similar question here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With