Until now we have checked the login credentials with UserName and password using following syntax.
logInWithUsernameInBackground
[PFUser logInWithUsernameInBackground:[UsernameField.text lowercaseString] password:PasswordField.text block:^(PFUser* user, NSError* error){
But now my requirement is that:
User must need to login with any one of both email and UserName.
And we need to check with username / email and password
How can this be achieved?
PFQuery *query = [PFUser query];
[query whereKey:@"email" equalTo:UsernameField.text];
[query findObjectsInBackgroundWithBlock:^(NSArray *objects, NSError *error){
if (objects.count > 0) {
PFObject *object = [objects objectAtIndex:0];
NSString *username = [object objectForKey:@"username"];
[PFUser logInWithUsernameInBackground:username password:PasswordField.text block:^(PFUser* user, NSError* error){
}];
}else{
[PFUser logInWithUsernameInBackground: UsernameField.text password:PasswordField.text block:^(PFUser* user, NSError* error){
}];
}
}];
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With