diff options
Diffstat (limited to 'Source')
-rw-r--r-- | Source/SPKeychain.m | 35 |
1 files changed, 35 insertions, 0 deletions
diff --git a/Source/SPKeychain.m b/Source/SPKeychain.m index f7580f65..cc98bf6c 100644 --- a/Source/SPKeychain.m +++ b/Source/SPKeychain.m @@ -213,6 +213,7 @@ */ - (BOOL)passwordExistsForName:(NSString *)name account:(NSString *)account { +#if __MAC_OS_X_VERSION_MAX_ALLOWED >= 1070 NSMutableDictionary *query = [NSMutableDictionary dictionary]; [query setObject:(id)kSecClassGenericPassword forKey:(id)kSecClass]; @@ -225,6 +226,40 @@ CFDictionaryRef result = NULL; return SecItemCopyMatching((CFDictionaryRef)query, (CFTypeRef *)&result) == errSecSuccess; +#else + SecKeychainItemRef item; + SecKeychainSearchRef search = NULL; + NSInteger numberOfItemsFound = 0; + SecKeychainAttributeList list; + SecKeychainAttribute attributes[2]; + + // Check supplied variables and replaces nils with empty strings + if (!name) name = @""; + if (!account) account = @""; + + attributes[0].tag = kSecAccountItemAttr; + attributes[0].data = (void *)[account UTF8String]; // Account name + attributes[0].length = (UInt32)strlen([account UTF8String]); // Length of account name (bytes) + + attributes[1].tag = kSecServiceItemAttr; + attributes[1].data = (void *)[name UTF8String]; // Service name + attributes[1].length = (UInt32)strlen([name UTF8String]); // Length of service name (bytes) + + list.count = 2; + list.attr = attributes; + + if (SecKeychainSearchCreateFromAttributes(NULL, kSecGenericPasswordItemClass, &list, &search) == noErr) { + while (SecKeychainSearchCopyNext(search, &item) == noErr) + { + CFRelease(item); + numberOfItemsFound++; + } + } + + if (search) CFRelease(search); + + return (numberOfItemsFound > 0); +#endif } /** |