Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7538085
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T07:01:30+00:00 2026-05-30T07:01:30+00:00

I am trying to authenticate a user by sending a POST request from my

  • 0

I am trying to authenticate a user by sending a POST request from my iOS app to a php script. Then having the iOS app read the NSHTTPURLResponse to determine whether or not it was successful. My iOS code is shown below, for some reason it says that my NSURLConnection is unused. The int code always shoots back a value of 200.

- (void)authenticateUser:(NSString *)aUsername
                password:(NSString *)aPassword
{
    NSString *post = [NSString stringWithFormat:@"username=%@&pw=%@", aUsername, aPassword];
    NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
    NSString *postLength = [NSString stringWithFormat:@"%d", [post length]];

    NSURL *url = [NSURL URLWithString:@"http://XXX.com/query-db.php"];
    NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url cachePolicy:NSURLRequestUseProtocolCachePolicy timeoutInterval:60.0];
    [request setHTTPMethod:@"POST"];
    [request setValue:postLength forHTTPHeaderField:@"Content-Length"];
    [request setHTTPBody:postData];

    NSURLConnection *theConnection = [NSURLConnection connectionWithRequest:request delegate:self];
}

- (void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response{
    NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;
    int code = [httpResponse statusCode];

    // Log the response
    NSLog(@"%d", code);
    if(code == 1){
        NSLog(@"received a 1");
        [self updateWorkTime];
        //[self close];
    } else {
        UIAlertView *alert = [[UIAlertView alloc] initWithTitle:@"Unsuccessul Attempt" message:@"The username or password is invalid, please try again." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil];
        [alert show];
        [alert release];
    }
}

Additionally, if you want to take a look at my php script, which I entered in dummy variables for and tested to see if it queried the database properly and that checked out… But just in case you’re curious.

<?php
    $sentUsername = $_POST['username'];
    $sentPW = $_POST['pw'];

    mysql_connect("xxx", "xxx", "xxx") or die(mysql_error());   
    mysql_select_db("xxx") or die(mysql_error());

    $result = mysql_query("SELECT * FROM Table") or die(mysql_error());  

    $authenticate = 0;

    while($authenticate == 0) {
        $row = mysql_fetch_array($result);
        $selectedUsername = $row['username'];
        $selectedPW = $row['pw'];
        $pwComp = strcmp($sentPW, $selectedPW);
        $userComp = strcmp($selectedUsername, $sentUsername);

        if(!$row) break;
        if($selectedPW == $sentPW && $selectedUsername == $sentUsername) {
            $authenticate = 1;
        }
    }
    echo $authenticate;
?>

I tried to set the PHP header, but I was unsure how to do that. I appreciate any and all help this community has given me, truly invaluable. Thanks!

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-30T07:01:32+00:00Added an answer on May 30, 2026 at 7:01 am

    The ‘200’ code you’re getting back is the HTTP status code, indicating that the request was successful.

    If you’re after the ‘1’ or ‘0’ value being sent back from your PHP script, you should look for it in the didReceiveData: delegate method, not didReceiveResponse:.

    - (void)connection:(NSURLConnection *)connection didReceiveData:(NSData *)theData
    {
        NSLog(@"authenticate value => %@",[[NSString alloc] initWithData:theData encoding:NSUTF8StringEncoding]);
    }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to authenticate user by sending a key and a random number
I'm trying to authenticate a user through the RESTful API (not Connect) but I
I'm trying to authenticate to a web server from an android class with the
Im trying to create a iPhone Objective C login page using PHP/MySQL to authenticate.
Google App Engine says Must authenticate first. while trying to deploy any app: me@myhost
I'm trying to authenticate a user against Active Directory using the types in the
I'm trying to authenticate a user on my symfony2 server. The authentication works with
I do not know much about encrypting. I am trying to use authenticate user
I'm trying to convert a user ID from a User class and store it
I'm trying to authenticate againest an ldap server I've created. The user password is

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.