NSString *GetPassword(NSString *userName, NSString *hostName) {
        if (!hostName.length || !userName.length) return nil;
        
        const char *serviceName = [hostName UTF8String];
        const char *serviceUserName = [userName UTF8String];
        const char *path = "";
        
        UInt32 passwordLength = 0;
        char *pass = nil;
        
        OSStatus status = noErr;
        SecKeychainItemRef itemRef;
        
        if ([hostName rangeOfString:@"mac"].location != NSNotFound) {
                serviceName = "iTools"; //<= note this
                status = SecKeychainFindGenericPassword(NULL,
                                                                                
                (UInt32)strlen(serviceName),
                                                                                
                serviceName,
                                                                                
                (UInt32)strlen(serviceUserName),
                                                                                
                serviceUserName,
                                                                                    
            &passwordLength,
                                                                                    
            (void **)&pass,
                                                                                    
            &itemRef);
        }else {
                status = SecKeychainFindInternetPassword(NULL,
                                                                                
                 (UInt32)strlen(serviceName),
                                                                                
                 serviceName,
                                                                                
                 0,
                                                                                
                 NULL,
                                                                                
                 (UInt32)strlen(serviceUserName),
                                                                                
                 serviceUserName,
                                                                                
                 (UInt32)strlen(path),
                                                                                
                 path,
                                                                                
                 0,
                                                                                
                 kSecAuthenticationTypeAny,
                                                                                
                 kSecAuthenticationTypeAny,
                                                                                    
             &passwordLength,
                                                                                    
             (void **)&pass,
                                                                                    
             &itemRef);
        }
        
        if (status != noErr) {
                CFStringRef errMess = SecCopyErrorMessageString(status, NULL);
                NSLog(@"%@", (NSString *)errMess);
                CFRelease(errMess);
                return nil;
        }
        
return [[[NSString alloc] initWithBytes:pass length:passwordLength encoding:NSUTF8StringEncoding] autorelease];
}

On May 31, 2010, at 12:11 AM, Jn wrote:

Would you have the API code to retrieve it? Not sure what to pass to get the mobile me password.

--
Chris

On 31/05/2010, at 2:43 AM, Jens Alfke <j...@mooseyard.com> wrote:


On May 30, 2010, at 12:55 AM, Chris Idou wrote:

OK, I see. So is Mobile-Me the only special case, or is there a more general rule about other places to find smtp server passwords?

AFAIK it’s the only special case. In general, an SMTP server’s password is stored under that server name in the keychain, as you’d expect.

—Jens




_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/palacios.dante%40gmail.com

This email sent to palacios.da...@gmail.com

All the best,
Dante.



_______________________________________________

Cocoa-dev mailing list (Cocoa-dev@lists.apple.com)

Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com

Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/cocoa-dev/archive%40mail-archive.com

This email sent to arch...@mail-archive.com

Reply via email to