Welcome to the Treehouse Community
Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.
Looking to learn something new?
Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.
Start your free trialThomas Tesla
3,205 PointsLoginViewController - 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
3,205 PointsGOT 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 :)
Camilo Castro
Courses Plus Student 2,549 PointsMust 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
3,205 PointsI 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.
Camilo Castro
Courses Plus Student 2,549 PointsPlease, post your code. :)
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
3,205 PointsAlso, 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.
Camilo Castro
Courses Plus Student 2,549 PointsThats 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