Created
April 16, 2015 19:57
-
-
Save lemonmojo/e4d6f93075fe6d3a91a1 to your computer and use it in GitHub Desktop.
OS X Proxy Password
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
+ (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