0

i have been working on an sms application and i want to provide some private space for the user... which can only be accessed if the user enters the right username and password...how can i accomplish that....? somebody told me that i can use the AccountManager but how can i link it with my class or activity on which i am going to put the password....

public class PrivateSpace extends Activity{

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        // TODO Auto-generated method stub
        super.onCreate(savedInstanceState);

any help will be appreciated...

kashifmehmood
  • 127
  • 1
  • 14

1 Answers1

0

I think it can be easily achieved by using shared preferences.. to store the password for your application like this..

  SharedPreferences settings = getSharedPreferences("my_shared_pref", 0);
  String password = settings.getString("password", "empty");
  if(password == "empty"){

   //store the value in your edittext as password

   }
 else{
    //if string in edittext matches with the password value.. let the user enter the activity.. else make a toast of wrong password..
 }
5hssba
  • 8,079
  • 2
  • 33
  • 35
  • but the shared preferences can b accessed without password that can be a problem – kashifmehmood Apr 15 '12 at 10:36
  • These shared preferences can be accessed only by your application.. as they are created in private mode..("my_shared_pref", 0); here 0 indicates private mode.. so only code in this application can access these shared preferences – 5hssba Apr 15 '12 at 10:41
  • and it would also contain the old password that is in effect – kashifmehmood Apr 15 '12 at 10:45
  • yes it will contain only one password.. and it will check if it is matching.. and allow the user.. if you want to change the password.. use sharedpreferences.Editor to edit the values ion preferences.. – 5hssba Apr 15 '12 at 10:49
  • wont they contain the password like the edittextpref contains the text when it is opened again...?? – kashifmehmood Apr 15 '12 at 10:50
  • is there any way that once the password is retrieved from the preference it clears the value in the preference...? – kashifmehmood Apr 15 '12 at 10:52