How to Use Keychain for Saving Password Like Generickeychain Sample Code

How to add another password into iOS Keychain?

I doubt if that can be done.... at max you can create two username with the second userame havinge "_passcode" attached to it and save the passcode to it...

for eg:

username: ankit
password: 1234

save this to keychain

and then again save another pair using

username: ankit_passcode
passcode: 4321

you can then retrieve it using the username provided...

hoping this helps.

fetching all items in keychain in one shot?

I believe you're slightly misreading that example. In GenericKeychain, they're not fetching "all items." They're fetching just one item and its one value. A keychain item is made up of properties, which are semi-public, and a "value" which is protected. Reading out of the keychain is fantastically expensive (much, much slower than reading a file off of disk; it's really shockingly slow). So the example is avoiding re-reading it when not needed. But it's not reading the entire keychain; just the one item that stores its data.

login and register using keychain

Here can you find apple's KeyChainItemWrapper class: https://developer.apple.com/library/ios/samplecode/GenericKeychain/Listings/Classes_KeychainItemWrapper_m.htm

You can use it like:

 KeychainItemWrapper *keychainItem = [[KeychainItemWrapper alloc] initWithIdentifier:@"YourAppLogin" accessGroup:nil];

// Set the username and password using:
[keychainItem setObject:@"password you are saving" forKey:@"Password"];
[keychainItem setObject:@"username you are saving" forKey:@"Username"];

// Get them
NSString *password = [keychainItem objectForKey:@"Password"];
NSString *username = [keychainItem objectForKey:@"Username"];

// Delete them
[keychainItem resetKeychainItem];

Does the Keychain in iOS actually work?

I've found SFHFKeychainUtilities to be an extremely helpful wrapper. It provides a very simple API that looks like this:

[SFHFKeychainUtils storeUsername:usernameInput andPassword:passwordInput forServiceName:@"foo" updateExisting:TRUE error:&error];

Here's a useful tutorial: http://gorgando.com/blog/tag/sfhfkeychainutils

Works all the time for me.

Good luck!



Related Topics



Leave a reply



Submit