androidBeginner
androidBeginner

Reputation: 197

Android SharedPreferences Password

I just wanted to ask if it is a good idea to store a password (encrypted) in the SharedPreferences. In Android you can delete the sharedPredPref for an application and then the password is gone, so it is better to store it in a database like sqlite? In my application I saved it in a sharedPref, so when starts an activity for the first time, he must set a new password. Now the problem is that, someone else can just delete the sharedPreferences and then he will just asked again to set a new password.

Upvotes: 0

Views: 1321

Answers (3)

Piyush Agarwal
Piyush Agarwal

Reputation: 25858

Use MODE_PRIVATE in shared preferences so nobody can access it except your application

SharedPreferences prefs= getSharedPreferences("yourpasspreference", MODE_PRIVATE);

Better to save the password kind of thing in encrypted form.

To protect clearing the data from settings you can use this in your manifest

<application android:label="MyApp" android:icon="@drawable/icon" 
           android:manageSpaceActivity=".ActivityOfMyChoice">

It will Disable the Clear Data Button in Settings, Manage Space button will be shown instead which launches the ActivityOfMyChoice Activity defined by you.

Upvotes: 0

madlymad
madlymad

Reputation: 6540

In android SharedPreferences as well as SQLite are both cleared when in application screen you press Clear data button. So there is no difference in that!

The user in that case would be logged out just as the first time he starts the application. Final authentication should always happen at server-side, not inside the app.

Upvotes: 1

VM4
VM4

Reputation: 6499

If your only concern is that someone might delete the preference xml file then storing them in SQLite will make no difference. Because both of these are deleted when you clear data for an app.

Upvotes: 0

Related Questions