Skip to content

Instantly share code, notes, and snippets.

@lemonmojo
Created April 16, 2015 19:57
Show Gist options
  • Save lemonmojo/e4d6f93075fe6d3a91a1 to your computer and use it in GitHub Desktop.
Save lemonmojo/e4d6f93075fe6d3a91a1 to your computer and use it in GitHub Desktop.
OS X Proxy Password
+ (NSString*)passwordForProxy:(NSString*)proxy port:(int)port user:(NSString*)user protocol:(SecProtocolType)protocol {
void *password;
UInt32 passwordLength = 0;
NSString *passwordStr = nil;
OSStatus status = SecKeychainFindInternetPassword(NULL,
(int)[proxy length], [proxy UTF8String], 0, NULL,
(int)[user length], [user UTF8String], 0, NULL,
port, protocol,
kSecAuthenticationTypeAny,
&passwordLength, &password, NULL);
if (status == noErr) {
if (password) {
passwordStr = [[[NSString alloc] initWithBytes:password length:passwordLength encoding:NSUTF8StringEncoding] autorelease];
SecKeychainItemFreeContent(NULL, password);
}
}
return passwordStr;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment