rafavinu
rafavinu

Reputation: 305

Compare password field IoS Swift

I am using a simple parse application to compare the user id password before they login. Here is the code i am using.

query.whereKey("email", equalTo: self.EmailField.text);
query.whereKey("password", equalTo: self.PasswordField.text);
query.findObjectsInBackgroundWithBlock { (objects, error) -> Void in
   if error == nil {
        println("\(objects?.count)");
        if(objects?.count==0){
                println("Invalid");
            }
            else{
                println("Valid");
            }
        } else {
            println("Error:")
        }
    }

When i use only the email query it is retrieving correctly and i am able to get Valid printed. However, when i enter both username and password, then it goes to Invalid even though the value entered are correct.

Note: The password field is a hidden field in parse. Please let me know where i am going wrong!

Upvotes: 0

Views: 851

Answers (1)

Lamour
Lamour

Reputation: 3040

I think you are doing too much work because this method below actually check the username and password.

PFUser.logInWithUsernameInBackground("myname", password:"mypass") {
 (user: PFUser?, error: NSError?) -> Void in
 if user != nil {
// Do stuff after successful login.
 } else {
// The login failed. Check error to see why.
 }

}

Upvotes: 2

Related Questions