In iOS, how to programmatically transfer username / password to a secure site

As you can, in iOS, programmatically access a password-protected site that has been protected by .htaccess or access control.

Using NSURLRequest, you can make a GET request with a URL. But if the URL is protected, how would you send a pair of username password. Also, what if it is encrypted using standard MD5 encryption.

+3
source share
1 answer

Add something like this to your HTTPConnectionDelegate:

-(void)connection:(NSURLConnection *)aConnection didReceiveAuthenticationChallenge:(NSURLAuthenticationChallenge *)challenge {
        if ([challenge previousFailureCount] == 0) {
                NSURLCredential *newCredential;
                newCredential = [NSURLCredential credentialWithUser:username password:password persistence:NSURLCredentialPersistenceNone];
                [[challenge sender] useCredential:newCredential forAuthenticationChallenge:challenge];
        } else {
                [[challenge sender] cancelAuthenticationChallenge:challenge];
        }
}
+8
source

Source: https://habr.com/ru/post/1703874/


All Articles