Advertise Mobile SDKs Books Events Forum News Social Networking Support Us
Follow @iphonedevsdk on Twitter

Interface 2, Advanced iOS
Mockup & Code Gen
($9.99)

Make your own iPhone apps
and run them live!
(free)

Pic Frame Dynamo: Photo Editing
($0.99)

Abiliator
($1.99)

Want your application or service advertised on iPhone Dev SDK?

Go Back   iPhone Dev SDK Forum > iPhone SDK Development Forums > iPhone SDK Development

Reply
 
LinkBack Thread Tools Display Modes
Old 12-01-2011, 06:02 AM   #1 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 97
iphone.savvy is on a distinguished road
Default Sending Username and Password to the webservice

Dear Experts,

I have to send the username & password to the webservice that will check the authentication with the login credentials stored at the SqlServer database.
The webservice return the response in XML.

My question is do i have to establish connection with webservice before sending username and password to the webservice?

How can i package the request with the username and password?

Thx in advance.
iphone.savvy is offline   Reply With Quote
Old 12-01-2011, 06:19 AM   #2 (permalink)
Cocoa Junkie
 
Duncan C's Avatar
 
Join Date: Dec 2008
Location: Northern Virginia
Posts: 6,003
Duncan C has a spectacular aura about
Default

Quote:
Originally Posted by iphone.savvy View Post
Dear Experts,

I have to send the username & password to the webservice that will check the authentication with the login credentials stored at the SqlServer database.
The webservice return the response in XML.

My question is do i have to establish connection with webservice before sending username and password to the webservice?

How can i package the request with the username and password?

Thx in advance.

You'll need to talk to the designer of the webservice.

It's pretty common to create a formatted HTTP url that invokes a PHP file on the server, with the username and password as parameters. You can use HTTPS for security if need be. The command might look something like this:

Code:
http://host.com/login.php?username=John%20Doe?password=somepassword
Your code would take the username and password from the user and encode them using percent escapes (where characters like spaces, slashes, brackets, question marks, or other characters that you use as delimiters in your URL are converted to %xx format). You would then insert the username and password into the URL and set it to the host using an NSURLConnection object, or using a third party library like ASIHTTPRequest. The webservice would send back a reply, which would come in as if it was a file in response to your request. You would then need to parse the XML response, using one of various XML libraries. There is one built into iOS, NSXMLParser. There's also libxml, which is a library of C functions. There are others as well. You'll need to do some research to figure out which best meets your needs.
__________________
Regards,

Duncan C
WareTo

Check out our apps in the Apple App store


Check out this password generator app that shows various techniques including using a data container singleton object to share data between objects in your project.

See this tutorial on using UIView animations and layer animations:

See this thread on generating random, non-repeating text

Check out a very cool Macintosh Kaleidoscopes app called ScopeWorks that we released to the Mac App store.

Last edited by Duncan C; 12-01-2011 at 06:23 AM.
Duncan C is online now   Reply With Quote
Old 12-01-2011, 11:25 AM   #3 (permalink)
Nuisance Developer
 
Join Date: Jul 2009
Location: Italy
Posts: 4,691
dany_dev is on a distinguished road
Default

you can start reading WebService [How-To]
__________________
dany_dev is offline   Reply With Quote
Old 12-01-2011, 11:49 AM   #4 (permalink)
Registered Member
 
Join Date: Dec 2010
Location: Seattle, WA
Posts: 408
RickSDK is on a distinguished road
Default

Here's a function i wrote that I use to send username and password to a webservice. It uses Post instead of Get which is nice because it won't crap out if someone includes special characters in their password.

Code:
+(NSString *)getResponseFromServerUsingPost:(NSString *)weblink:(NSArray *)fieldList:(NSArray *)valueList
{
	if([fieldList count] != [valueList count]) {
		return @"Invalid value list!";
	}
	int i=0;
	NSMutableString *fieldStr;
	fieldStr = [NSMutableString stringWithCapacity:256];
	for(NSString *name in fieldList)
		[fieldStr appendFormat:@"&%@=%@", name, [valueList objectAtIndex:i++]];
	
	NSString *responseString = nil;
	NSData *postData = [fieldStr dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
	NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
	NSURL *url = [NSURL URLWithString:weblink];
	NSMutableURLRequest *request = [[NSMutableURLRequest alloc] initWithURL:url
																cachePolicy:NSURLRequestReloadIgnoringCacheData timeoutInterval: 10];
	
	[request setHTTPMethod:@"POST"];
	[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
	[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
	[request setHTTPBody:postData];
	NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request delegate:self];
	
	if(connection) {
		NSLog(@"Web Connection Established");
		NSData *response = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:nil];
		responseString = [[NSString alloc] initWithData:response encoding:NSUTF8StringEncoding];
	} else {
		[ProjectFunctions showAlertPopup:@"WebService Error" :@"Not able to connect to the server. Try again later."];
	}
	
	
	[connection release];
	[request release];
	return responseString;
}
__________________
Check out my apps


Last edited by RickSDK; 12-01-2011 at 11:53 AM.
RickSDK is offline   Reply With Quote
Old 12-01-2011, 01:02 PM   #5 (permalink)
Indie Developer
 
iSDK's Avatar
 
Join Date: Jul 2010
Posts: 1,346
iSDK is on a distinguished road
Send a message via AIM to iSDK
Default

Quote:
Originally Posted by Duncan C View Post
You'll need to talk to the designer of the webservice.

It's pretty common to create a formatted HTTP url that invokes a PHP file on the server, with the username and password as parameters. You can use HTTPS for security if need be. The command might look something like this:

Code:
http://host.com/login.php?username=John%20Doe?password=somepassword
Your code would take the username and password from the user and encode them using percent escapes (where characters like spaces, slashes, brackets, question marks, or other characters that you use as delimiters in your URL are converted to %xx format). You would then insert the username and password into the URL and set it to the host using an NSURLConnection object, or using a third party library like ASIHTTPRequest. The webservice would send back a reply, which would come in as if it was a file in response to your request. You would then need to parse the XML response, using one of various XML libraries. There is one built into iOS, NSXMLParser. There's also libxml, which is a library of C functions. There are others as well. You'll need to do some research to figure out which best meets your needs.
*
Code:
http://host.com/login.php?username=John%20Doe&password=somepassword
iSDK is offline   Reply With Quote
Old 12-02-2011, 01:21 AM   #6 (permalink)
Registered Member
 
Join Date: Aug 2010
Posts: 97
iphone.savvy is on a distinguished road
Default

Hi,

One more question,
If i have to send multiple requests to the web service then how i can send the requests without username and password. Because once the username and password are valid i want to hold this session till user logs out.
How to achieve this please advise .
iphone.savvy is offline   Reply With Quote
Old 12-02-2011, 02:20 AM   #7 (permalink)
Registered Member
 
Join Date: Jan 2011
Posts: 28
Mogglas is on a distinguished road
Default

Quote:
Originally Posted by iphone.savvy View Post
Hi,

One more question,
If i have to send multiple requests to the web service then how i can send the requests without username and password. Because once the username and password are valid i want to hold this session till user logs out.
How to achieve this please advise .
A quick search on google sent me back here to another thread: http://www.iphonedevsdk.com/forum/ip...hp-iphone.html

And just a tip. When sending login credentials, please do the following to make it at least a bit of an effort for anyone to try and hack you. Use Post instead of Get. And only send hashed and salted passwords, never send the original password to the webservice.
__________________
Games i've developed for iPhone so far:
Skycat and the StarchildrenRushing NinjasChicken Race
Mogglas is offline   Reply With Quote
Reply

Bookmarks

Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On



» Advertisements
» Online Users: 394
16 members and 378 guests
AppsBlogger, chiataytuday, Clouds, David-T, dedeys78, Duncan C, e2applets, EvilElf, heshiming, iekei, leostc, LunarMoon, Murphy, sacha1996, Sami Gh, teebee74
Most users ever online was 1,387, 04-10-2012 at 04:21 AM.
» Stats
Members: 175,676
Threads: 94,127
Posts: 402,912
Top Poster: BrianSlick (7,990)
Welcome to our newest member, jleannex55
Powered by vBadvanced CMPS v3.1.0

All times are GMT -5. The time now is 06:41 AM.
Powered by vBulletin® Version 3.8.0
Copyright ©2000 - 2012, Jelsoft Enterprises Ltd.
Search Engine Friendly URLs by vBSEO 3.3.0