Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8589087
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 11, 20262026-06-11T22:57:44+00:00 2026-06-11T22:57:44+00:00

I am trying the code to have login credentials saved using SharedPreferences. I am

  • 0

I am trying the code to have login credentials saved using SharedPreferences. I am able or believe the credentials are being saved successfully but when trying to login by comparing the credentials in edit to the ones saved. I keep receiving a “Wrong Password” error. Not sure what I am overlooking. the code to login is below.

Login:

   public class AccessApp extends Activity implements OnClickListener {
private SharedPreferences sp;
String user,pass;
Button lBttn,cBttn;
EditText uname,pword;
Intent i;

int flag=0;

/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{ 
    super.onCreate(savedInstanceState);
    setContentView(R.layout.main);
    lBttn=(Button)findViewById(R.id.login_button);
    cBttn=(Button)findViewById(R.id.cancel_button);
    uname=(EditText)findViewById(R.id.username);
    pword=(EditText)findViewById(R.id.password);

    lBttn.setOnClickListener(this);
    cBttn.setOnClickListener(this);
}
public void onClick(View arg0) {

    sp=this.getSharedPreferences("Register", MODE_WORLD_READABLE);
    user=sp.getString("USERNAME", "");
    pass=sp.getString("PASSWORD","");


    if(lBttn==arg0){
            if((uname.getText().toString().compareTo(user)==0)&& 
               (pword.getText().toString().compareTo(pass)==0))

            {
          Toast.makeText(this, "You are Logged In", 20000).show();

               Intent intent;
               intent=new Intent(this,details.class);
               startActivity(intent);
              flag=1;
            }

        else
           {
            Toast.makeText(this, "Wrong Username or Password",20000).show();
            flag=0;   
           }       
        } 

Register:

     public class SharedPrefLoginActivity extends Activity implements OnClickListener {

private SharedPreferences sp;

Intent i;
Button regBttn,rtnBttn;
EditText rName,rPwd;
String user,pass,cpass,chk;
String stat="a";


/** Called when the activity is first created. */
@Override
public void onCreate(Bundle savedInstanceState)
{


    super.onCreate(savedInstanceState);
    setContentView(R.layout.register);


    rName=(EditText)findViewById(R.id.reg_uname);
    rPwd=(EditText)findViewById(R.id.reg_pswd);
    regBttn=(Button)findViewById(R.id.reg_button);
    rtnBttn=(Button)findViewById(R.id.rtn_button); 

    regBttn.setOnClickListener(this);
    rtnBttn.setOnClickListener(this);
    sp=this.getSharedPreferences("AccessApp", MODE_WORLD_READABLE);
    chk=sp.getString("USERNAME", "");
    if(chk.length()!=0){
        sp=getSharedPreferences("AccessApp",MODE_WORLD_WRITEABLE); 

        i=new Intent(this,AccessApp.class);
        startActivity(i);      
    }

}

public void onClick(View arg0) {
    user=rName.getText().toString();
    pass=rPwd.getText().toString();
    if(arg0==regBttn){

        if((user.length()!=0))
        {
            if((pass.length()!=0))
            {

        sp=getSharedPreferences("AccessApp",MODE_WORLD_WRITEABLE);
        Editor myEditor=sp.edit();
        myEditor.putString("USERNAME", user);
        myEditor.putString("PASSWORD", pass);
        myEditor.commit();
        Toast.makeText(this, "Registration is successfull",10000).show();
        i=new Intent(this,AccessApp.class);
        startActivity(i);
        }
        else
         {
          Toast.makeText(this, "Please Enter password", 10000).show();  
         }
         }
        else{
            Toast.makeText(this,"Please Enter Username",10000).show();
         }
      }
  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-11T22:57:45+00:00Added an answer on June 11, 2026 at 10:57 pm

    The issue causing the issue is below

    login:

        sp=this.getSharedPreferences("Register", MODE_WORLD_READABLE); /* change "Register" to "AccessApp" */
    

    registration:

        sp=getSharedPreferences("AccessApp",MODE_WORLD_WRITEABLE);
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to Login or SugarCrm using REST. I have this code,, //Login
I am trying to connect to Webtrend's API using PHP but haven't been able
I am trying to connect bugzilla using java code.I have used the sample shown
I have been trying to develop a Core Data piece of code and have
I currently don't have code to show as an example because I been trying
I´m trying to code a tooltip (Yes I know, I have my reasons to
This is the code I have. I'm trying to insert a image to show
I am trying to call c# function from javascript the code i have tried
i have a sql server that i use and i am trying to code
I am trying to setup a few fixes in some code that have caught

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.