0

I'm using this code to send Post login to a page:

NSString *kode = Password.text;
NSString *post = [NSString stringWithFormat:@"user=%@&pass=%@&login=login", bruger.text, kode];
NSData *postData= [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [NSMutableURLRequest new];
[request setURL:[NSURL URLWithString:@"http://itskp-odense.dk/portal.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLResponse *response;
NSError *error;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *strdata=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];

if ([strdata rangeOfString:@"Log ud"].location != NSNotFound){
    //Hvis koden/bruger var fokert gør dette:
    response = nil;
    strdata = nil;
    request = nil;
    AppDelegate* appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
    appDelegate.sharedString = bruger.text;
    UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
    UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"second"];
    [self presentViewController:vc animated:YES completion:nil];
}else{
    UIAlertView *fejl = [[UIAlertView alloc] initWithTitle:@"Fejl Opstået" message:@"Dit brugernavn eller kode var fokert" delegate:Nil cancelButtonTitle:@"Prøv igen" otherButtonTitles: nil];
    [fejl show];
}

Then it sends me to another view by using this snippet:

UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *vc = [storyboard instantiateViewControllerWithIdentifier:@"second"];
[self presentViewController:vc animated:YES completion:nil];

I check if the strdata contains the string if it does then the login was successful and it switches views. Then i made a simple Log Out button that switches view back to the main view which is the login. Now if i input random data in the text field it will still allow me to switch views.

Let me try to explain this in another way. The code above allows me to send post data to the web page and i check the response for a string to determine if the person entered the correct information and it was successful login. Then if the string was found it switches views to a table view.

Then in the table view i created a log out button, all it does is a modal segue to the main view. Then without closing the application if i enter random data it will still switch the view to the table view, even if the information is incorrect. Doesn't matter what i type in the fields it's gonna send me to the next view, which it shouldn't since it's incorrect information and it don't see why it does that.

Thanks in advance.

Borys Verebskyi
  • 4,160
  • 6
  • 28
  • 42
Steelzeh
  • 284
  • 2
  • 13
  • try printing out your response – Preetam Jadakar Oct 25 '13 at 07:33
  • if I'm correct you only check the string for "log out", but not for anything else. so whatever gets through, you will not have pressed the "log out" button. Hence you'll be logged in. So check if you're checking the right stuff. – Tikkes Oct 25 '13 at 07:35

0 Answers0