Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Best method of secure Objective-C iPhone login

I wanted to know, the best methodology (with code sample please) of having a login feature on an iPhone application, that would connect to a server. I am assuming web service sending via SOAP isn't the safest.

Thanks guys

like image 815
Doz Avatar asked Jan 24 '23 06:01

Doz


1 Answers

With NSURLRequest / NSMutableURLRequest you can set up authentication using any method you like... here's an HTTP Basic example for getting some XML result.

  NSMutableURLRequest * request = [NSMutableURLRequest requestWithURL:url];
  [request setHTTPMethod:@"GET"]; // or POST or whatever
  [request setValue:@"application/xml" forHTTPHeaderField:@"Accept"];
  NSString * userID = @"hello";
  NSString * password = @"world";
  NSString * authStr = [[[NSString stringWithFormat:@"%@:%@", userID, password] dataUsingEncoding:NSUTF8StringEncoding] base64Encoding];
  [request setValue:[NSString stringWithFormat: @"Basic %@", authStr] forHTTPHeaderField:@"Authorization"];

You'll need to read up on HTTP authentication techniques to know what to do to talk to your specific server, but there's nothing wrong with using HTTPS (SSL) + Basic, it's secure.

like image 145
Simon Woodside Avatar answered Feb 01 '23 01:02

Simon Woodside