aryaxt
aryaxt

Reputation: 77626

Multiple Users in the Keychain

so I got my iPhone app to use the keyChain and store my password.

KeychainItemWrapper *kc = [[KeychainItemWrapper alloc] initWithIdentifier:@"Password"];
[kc SetObject:@"My_Password" forKey:(id)kSecAttrAccessGroup];
[kc release];

This saves my password correctly. I tried to pass a string (username) instead of (id)kSecAttrAccessGroup to relate the password to a specific username, but It crashes.

QUESTION: How can i relate the stored password to a username, because my app allows multipple user to login.

Upvotes: 1

Views: 1201

Answers (1)

Sandro Meier
Sandro Meier

Reputation: 3051

I know it's not really an answer to your quesiton. But I use SFHFKeychainUtils(Github).

It's also a wrapper and it allows you exactly what you are looking for. Store a password associated to a username. Here's some code how I did it with SFHFKeychainUtils.

NSString *username = @"Username";
NSString *password = @"Password";
[SFHFKeychainUtils storeUsername:username andPassword:password forServiceName:@"Your App" updateExisting:YES error:NULL];

Or pass an pointer to a NSError object if you want any error information. ;-) I hope my answer will help you...

Sandro Meier

Upvotes: 2

Related Questions