Android:ParseException:无效的登录凭据

时间:2015-01-01 19:42:30

标签: android login parse-platform passwords

我正在编写一个Android应用,可以将用户注册到Parse平台,并允许用户注册并登录该应用。我可以毫无问题地注册用户。但是,当我在Parse中检查我的_User表时,它表示密码未定义。此外,当我登录时,它会显示给我

-com.parse.ParseException:登录凭据无效

以下是注册用户的代码

protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_sign_up);
    //initialize parse with credentials
    register = (Button) findViewById(R.id.bSignUpConfirm);
    register.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            registerUser();
        }
    });
    ActionBar signUpActionBar = getActionBar();
    signUpActionBar.setBackgroundDrawable(new ColorDrawable(Color.RED));

}
public void registerUser(){
    getSignUpName = (EditText) findViewById(R.id.eGetSignUpName);
    getSignUpUsername = (EditText) findViewById(R.id.eGetSignUpUsername);
    getSignUpEmail = (EditText) findViewById(R.id.eGetSignUpEmail);
    getSignUpPassword = (EditText) findViewById(R.id.eGetSignUpPassword);
    getSignUpConfirmPassword = (EditText) findViewById(R.id.eGetSignUpConfirmPassword);
    signUpUsername = getSignUpUsername.getText().toString();
    signUpName = getSignUpName.getText().toString();
    signUpEmail = getSignUpEmail.getText().toString();
    signUpPassword = getSignUpPassword.getText().toString();
    signUpConfirmPassword = getSignUpConfirmPassword.getText().toString();
    ParseUser newUser = new ParseUser();
    newUser.setUsername(signUpUsername);
    newUser.setEmail(signUpEmail);
    newUser.put("fullName", signUpName);
    if(signUpPassword.equals(signUpConfirmPassword)){
    newUser.setPassword(signUpPassword);
    }else{
        Toast.makeText(getApplicationContext(), "Password does not match!", Toast.LENGTH_LONG).show();
    }
    newUser.signUpInBackground(new SignUpCallback() {
        @Override
        public void done(com.parse.ParseException e) {
            if (e == null){
                Intent finishRegistration = new Intent(SignUpActivity.this, MainScreen.class);
                startActivity(finishRegistration);
            }else{
                Toast.makeText(getApplicationContext(), "Connection to the server has failed.\n Please try again later.", Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }
        }
    });
}

以下是登录用户的代码

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_login);
    ActionBar loginBar = getActionBar();
    loginBar.setTitle("Sign In");
    loginBar.setBackgroundDrawable(new ColorDrawable(Color.RED));
    //initialize parse credentials
    Button logIn = (Button) findViewById(R.id.bSignIn);
    logIn.setOnClickListener(new View.OnClickListener() {
        @Override
        public void onClick(View v) {
            logIn();
        }
    });

}
public void logIn(){
    getLoginUsername = (EditText) findViewById(R.id.eGetLoginUsername);
    getLoginPassword = (EditText) findViewById(R.id.eGetLoginUsername);
    loginUsername = getLoginUsername.getText().toString();
    loginPassword= getLoginPassword.getText().toString();
    ParseUser.logInInBackground(loginUsername, loginPassword, new LogInCallback() {
        public void done(ParseUser user, ParseException e) {
            if (e == null) {
                loginSuccessful();
            } else {
                Toast.makeText(getApplicationContext(),"Wrong Email/Password Combination", Toast.LENGTH_LONG).show();
                e.printStackTrace();
            }
        }
    });

}
public void loginSuccessful(){
    Intent backToMainIntent = new Intent(LoginActivity.this, MainScreen.class);
    startActivity(backToMainIntent);
}

谢谢!

1 个答案:

答案 0 :(得分:1)

Parse仪表板上的密码值始终未定义,以阻止您查看用户密码。

我认为它不起作用,因为您的登录代码中存在错误。

getLoginUsername = (EditText) findViewById(R.id.eGetLoginUsername);
getLoginPassword = (EditText) findViewById(R.id.eGetLoginUsername);

这两个EditTexts都是相同的,即使一个用于密码而另一个用于用户名。我猜测密码EditText的ID是错误的。

希望这有帮助。