Hi Readers,
The keychain service provide a secure way to store content such as passwords, keys, certificates, etc. Each iOS app has a separate requirement to save items. There is a class named KeychainItemWrapper which provide you service to save data into keychain and retrieve it later as per the requirement. You need to first download KeychainItemWrapper class which is available in Apple library documents. After download these files include these into your project and follow below code to save username, password into keychain:
KeychainItemWrapper *keychain = [[KeychainItemWrapper alloc] initWithIdentifier:@"YourAppIdentifier" accessGroup:nil];
These lines will create with identifier same as your app identifier. Now you will save username and password as:
// Store username to keychain
[keychain setObject:@"usernameText" forKey:(id)kSecAttrAccount];
// Store password to keychain
[keychain setObject:@"passwordText" forKey:(id)kSecValueData];
We can later get values of these by following code:
//Get username
NSString *usernameText = [keychain objectForKey:(id)kSecAttrAccount];
//Get password
NSString *passwordText = [keychain objectForKey:(id)kSecValueData]
Thanks for reading.
0 Comment(s)