Welcome to the Treehouse Community

The Treehouse Community is a meeting place for developers, designers, and programmers of all backgrounds and skill levels to get support. Collaborate here on code errors or bugs that you need feedback on, or asking for an extra set of eyes on your latest project. Join thousands of Treehouse students and alumni in the community today. (Note: Only Treehouse students can comment or ask questions, but non-students are welcome to browse our conversations.)

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and a supportive community. Start your free trial today.

iOS Build a Self-Destructing Message iPhone App Using Parse.com as a Backend and Adding Users Logging In and Logging Out

Thomas Tesla
Thomas Tesla
3,205 Points

LoginViewController - Invalid Credentials always

No matter what, the login method always throws an error with message - "invalid login credentials" . The username and password are absolutely correct and I checked the same by NSLog also. Can someone help? Thank you :)

3 Answers

Thomas Tesla
Thomas Tesla
3,205 Points

GOT IT. I had made a small mistake in my storyboard for the signup scene. While creating the outlets for the textfield, i had by mistake overlapped the email with password. So my password is technically password+email; Thats why my login was never working. Fixed it now. Works like a charm.

Thanks a lot Camilo Castro for all the efforts :)

Must be something related to your Parse Backend.

Please check if you have the correct AppID and Client Keys. and the if user exists with the correct password.

Thomas Tesla
Thomas Tesla
3,205 Points

I checked the client key and appID provided in the appdelegate.m file with the one is parse.com . They both match. And my user name password also exists. Even now the signup process happens successfully. Its only the login process that doesn't seem to work.

Please, post your code. :)

Thomas Tesla
Thomas Tesla
3,205 Points
  • (IBAction)login:(id)sender

{

NSString *username = [self.usernameField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];
NSString *password = [self.passwordField.text stringByTrimmingCharactersInSet:[NSCharacterSet whitespaceAndNewlineCharacterSet]];

if([username length] ==0 || [password length] ==0)
{
    UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Oops!" message:@"Enter valid username & password" delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];
    [alertView show];
}

else{

// NSLog(username); // NSLog(password); [PFUser logInWithUsernameInBackground:username password:password block:^(PFUser *user, NSError *error) { if (error) {

            UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:@"Sorry!" message:
                                      [error.userInfo objectForKey:@"error"]delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil];

            [alertView show];


        } else {
            //NSLog(@"Works now");
            [self.navigationController popToRootViewControllerAnimated:YES];
        }
    }];
}

}

Thomas Tesla
Thomas Tesla
3,205 Points

Also, there's this wierd thing. I replaced the login code with my signup code. Set a value manually for the email id (cos the login screen doesnt have email textfield) . Now when i execute it, I provided a username ( here is used 'rocky') and a password and it got saved successfully i.e the signup code is perfect. Now i replace the code back to login code and executed it. This time the login works perfectly for username rocky. But other username passwords present in the dashboard gives " invalid login credentials" error :/ I have no idea why rocky alone works.

Thanks mate.

Thats pretty odd, the code looks right.

try to make a test with sample values

like this

- (void) testLogin {

    NSDictionary * user1 = @{@"name":@"rocky", @"pass":@"1234"};

    NSDictionary * user2 = @{@"name":@"foo", @"pass":@"bar"};

   NSArray * users = @[user1, user2];

  for(NSDictionary * user in users){

   [PFUser logInWithUsernameInBackground:user[@"name"] password:user[@"pass"] block:^(PFUser *user, NSError *error) { 
        NSLog(@"Testing %@", user);

        if(!error){
             NSLog(@"Login OK");
        } else {
             NSLog(@"%@", error);
        }

      [PFUser logOut];
   }]; 

  } // End for

} // End Test