Reputation:
How can I protect username and password saved in preferences?
Some sample code would be nice.
Upvotes: 0
Views: 157
Reputation: 3827
If you store passwords in plain text in an SQLite database or shared preferences, someone with root access might see them. Encrypting credentials prior to saving them locally would be safer, but still not perfect if someone reverse-engineers your app and gets the encryption key.
Have a look at the AccountManager. Also, this post might help you.
If you find that too complicated for your purpose, at least encrypt passwords before storing them into SharedPreferences! You can find more information, explanation and code here, too.
Upvotes: 1
Reputation: 5176
SharedPreferences sharedPreferences = MyApplication.getContext()
.getSharedPreferences(ApplicationConstants.SHARED_PREF_NAME,
Activity.MODE_PRIVATE);
Shared prefernces are stored under Android/data/data/yourApp on the internal file system of android and it's not accessible to other apps, so you can privately save data on shared preference
Upvotes: 0
Reputation: 6533
ACtually shared prefrence data store in your application memory and no other app can access that so beware of this
Upvotes: 0