I heard that using keychain is better than using NSUserDefault.
The problem is that I have no idea how to use it.
I'm trying to make a login and register for the users with all different passwords and usernames.
Can someone please demonstrate or screenshot the code for how to do it? oh and I'm using xcode 4.6
Asked
Active
Viewed 150 times
1
Hemant Singh Rathore
- 2,153
- 1
- 24
- 38
anika
- 73
- 7
-
Find a wrapper. There are some already – Stephen J Aug 26 '14 at 00:14
-
do you mean through github? – anika Aug 26 '14 at 00:23
-
Why don't you use SQLite, Core Data or anything to do with database? – Goppinath Sep 13 '14 at 10:45
-
@Goppinath I tried but I kept getting mach o-linker errors for some reason. – anika Sep 14 '14 at 14:56
2 Answers
1
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];
Christiaan Beekhuizen
- 236
- 2
- 6
0
NSUserDeafults store data within the app and Key-chain stores data in iOS keychain.
You can use SSKeyChain.
It's use easy and works with both ARC and Non-ARC.
Also check this How to choose account and service values for SSKeychain
Community
- 1
- 1
Hemant Singh Rathore
- 2,153
- 1
- 24
- 38