For Login Authentication ,using ASIFormDataRequest Follow the following STEPS
1) Create one webservice which can match User Name and Password from server and give the response if Username and Password is correct Give response "Success" ELSE "Fail".
For Example : https://www.yoursite.com/login1.php?username=%@&password=%@
2) Create one url using UsernameTextfield.text and PasswordTextfield.text like this
NSURL *url1 = [NSURL URLWithString:[NSString stringWithFormat:@"https://www.yoursite.com/login1.php?username=%@&password=%@",Ustr,Pstr]];
Where Ustr and Pstr are NSString from Both text fields.
3) Create ASIFormDataRequest
- (IBAction)fetchTopSecretInformation:(id)sender{
Ustr = User.text;
Pstr = Pass.text;
NSURL *url1 = [NSURL URLWithString:[NSString stringWithFormat:@"https://www.yoursite.com/login1.php?username=%@&password=%@",Ustr,Pstr]];
ASIFormDataRequest *request1 = [ASIFormDataRequest requestWithURL:url1];
[request1 setUseKeychainPersistence:YES];
request1.delegate = self;
request1.shouldPresentCredentialsBeforeChallenge = YES;
[request1 setRequestMethod:@"POST"];
[request1 setPostValue:User.text forKey:@"User Name"];
[request1 setPostValue:Pass.text forKey:@"Password"];
[request1 setTimeOutSeconds:30];
[request1 setDidFailSelector:@selector(topSecretFetchFailed:)];
[request1 setDidFinishSelector:@selector(topSecretFetchComplete:)];
[request1 startAsynchronous];
}
Connect this method with Sign In Button in xib.
- (IBAction)topSecretFetchFailed:(ASIHTTPRequest *)theRequest{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Error" message:@"Error sending request to the server" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
[alert show];
}
- (IBAction)topSecretFetchComplete:(ASIHTTPRequest *)theRequest{
NSString *strResponse = [[theRequest responseString] stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
strFinal = [theRequest responseString];
NSLog(@"Sattus Code : %@",[theRequest responseString]);
NSString *failStr = @"failed";
NSString *successStr = @"successfully";
if ([strFinal isEqualToString:successStr]) {
ViewController *view = [[ViewController alloc] initWithNibName:@"ViewController" bundle:nil];
[self.navigationController pushViewController:view animated:YES];
}else
if ([strFinal isEqualToString:failStr]) {
UIAlertView *AlertFail = [[UIAlertView alloc] initWithTitle:@"LogIn Failed !" message:@"Wrong ID or Password" delegate:self cancelButtonTitle:@"Ok" otherButtonTitles:nil, nil];
[AlertFail show];
}
}
So if success go to next page otherwise Alert warning .....