Search code examples
javaandroidandroid-intentauthenticationpasswords

how to make a password constant?


I'm Developing an Android app in which there is a Login activity and a Questionnaire activity. So now I wanted to make the user to access the app only by entering the unique id which will help in blocking unauthorized users. I tried with the code but when i press the login button it pops the alert dialogue even if the password is matching the password I've given. And the password i wanted to keep is 'VISTEON'. If the password entered is rite then it should intent to the next activity.

check my java code and help me to modify it.

this is my Login activity

Here is my java code

public class Klogin extends Activity {
EditText editText1;
Button login;

@Override
protected void onCreate(Bundle savedInstanceState) {
    super.onCreate(savedInstanceState);
    setContentView(R.layout.activity_main_login);
    addButtonListener();
}
public void addButtonListener()
{
    Button login=(Button)findViewById(R.id.button1);
    login.setOnClickListener(new OnClickListener(){
        public void onClick(View v){
            if(validationSuccess()){
                 Intent intent = new Intent(Klogin.this, Login.class);
                 startActivity(intent);
             }
         }
     });
    
     
    }

private Boolean validationSuccess()
{
    EditText visteon = null;
    if(editText1==visteon)
    {
        alertDialog();
        return false;
    }
    
     return true;
 }
 private void alertDialog()
 {
     AlertDialog.Builder alertDialogBuilder = new AlertDialog.Builder(Klogin.this);
        alertDialogBuilder.setMessage("Please ENTER the Correct password").setCancelable(false).setPositiveButton("OK", new DialogInterface.OnClickListener()
        {
                    public void onClick(DialogInterface dialog, int id) 
                    {
                        dialog.cancel();
                    }
                });

            AlertDialog alert = alertDialogBuilder.create();
            alert.show();

 }

Solution

  • Try this..

    public void addButtonListener()
    {
         Button login=(Button)findViewById(R.id.button1);
         editText1=(EditText)findViewById(R.id.editText1);
         login.setOnClickListener(new OnClickListener(){
            public void onClick(View v){
                if(validationSuccess(editText1.getText().toString().trim())){
                     Intent intent = new Intent(Klogin.this, Login.class);
                     startActivity(intent);
                 }
             }
         });
    }
    

    and

    private Boolean validationSuccess(String value)
    {
        if(!value.equals("VISTEON"))
        {
            alertDialog();
            return false;
        }
    
         return true;
     }