help with simple use of keychain framework
Status: Abandoned
Brought to you by:
wadetregaskis
|
From: Mark K. <ma...@bg...> - 2004-08-02 17:13:29
|
Hi. Is there any documentation for the Keychain Framework? I am trying
to use it in a simple Cocoa app but have been unsuccessful. What I am
trying to do is, for a given service name, look up the keychain entry
(the first one that matches would be fine), and get both the user name
and password from it. Below is the code.
Any help would be most welcome.
Mark
Keychain *keychain;
KeychainItem *keychainItem;
NSArray *keychainSearchResultsArray;
NSString *accountName, *accountPassword;
keychain = [Keychain defaultKeychain]; // get default keychain.
keychainSearchResultsArray = [[[KeychainSearch
keychainSearchWithKeychain:keychain] setService:hostName] retain];
//*** This returns nil always!!! Why?
if (keychainSearchResultsArray != nil) {
keychainItem = [keychainSearchResultsArray objectAtIndex:0]; // get
acct & pw from first item.
accountName = [keychainItem account];
NSLog(@"account name is %@",accountName);
[loginUser setStringValue:accountName];
[loginPassword setStringValue:[keychain
passwordForGenericService:hostName forAccount:accountName]];
NSLog(@"password is %@",[keychain passwordForGenericService:hostName
forAccount:accountName]);
}
|