creating a simple login

Discussion in 'iOS Programming' started by Dman90, Nov 11, 2011.

  1. Dman90, Nov 11, 2011
    Last edited: Nov 11, 2011

    Dman90 macrumors newbie

    Jun 25, 2011
    Hi Guys,

    Im having difficulty setting up a simple login view.

    this is my login method:

        NSString *myURL = [ NSString stringWithFormat: @"", usernameField.text, passwordField.text]; 
        NSData *data = [NSData dataWithContentsOfURL: [NSURL URLWithString:myURL]]; 
        NSString *Str = [[NSString alloc] initWithBytes: [data bytes] length:[data length] encoding: NSUTF8StringEncoding]; 
        if([Str isEqualToString:@"Wrong password"]){
            NSLog(@"LOGIN INCORRECT");}
        else {
            NSLog(@"Login SUCCESS !!!");}
    this is the php file i use to connect to the database:


    $checkPwdQuery=mysql_query("SELECT password FROM users WHERE user='$user'"); 
    if (
    die (
    'Password match');} 
    die (
    'Wrong password');} 
    I have tried a few different methods but don't seem to get anywhere. ANy help would be appreciated.

  2. dejo Moderator


    Staff Member

    Sep 2, 2004
    The Centennial State
    You should probably provide more info on what's not working: what are you expecting to happen vs. what did happen.

    But, for now I'll leave you with this: "Wrong Password" != "Wrong password"
  3. subsonix macrumors 68040

    Feb 2, 2008
    Isn't it a better idea to use the keychain than to store user login in plain text?
  4. Dman90 thread starter macrumors newbie

    Jun 25, 2011
    well to test this, when i type the wrong password I want the 'wrong password' comment to show up. Right now for every input its always a success, because the code is set up to be a success for anything other then the wrong password. This tells me its not working.
  5. subsonix macrumors 68040

    Feb 2, 2008
    Switch the order then. ;)

        if([Str isEqualToString:@"Correct password"]){
            NSLog(@"Login SUCCESS !!!");}
        else {
            NSLog(@"LOGIN INCORRECT");}
  6. Dman90 thread starter macrumors newbie

    Jun 25, 2011
    I don't think you understand. the order itself is irrelevant.

    I don't think that the database link is working, and does anyone know why from looking at the PHP code.

  7. chown33 macrumors 604

    Aug 9, 2009
    Sailing beyond the sunset
    If you're trying to debug your PHP code, you're on the wrong forum. Consider asking your PHP-related question on the Web Development forum.

    What testing have you done on your PHP code? As a test, enter this command-line in Terminal:
    curl ""
    What does the output say? Is it one of your expected strings? If your PHP code is working, it should be, because the 'curl' command is making the same kind of HTTP request as your Objective-C code.

    If the output isn't one of your expected strings, then what does the output tell you?

    You need to test your PHP code separate from the iOS code. The curl command can do some of this, for many simple queries. I suggest reading its man page and trying it out with a name and password that you have in your database.

    Finally, the security design of this code is awful. You're sending a password in cleartext, over an unencrypted connection. I hope it's not protecting anything of consequence.

Share This Page