johnjay22113
johnjay22113

Reputation: 123

How to prevent SharedPreferences from being changed

I'm worried about android security. I am storing the user id in sharedpreferences. I see some programs online that allow you to get into the sharedpreferences if your device is rooted... etc...

How do I prevent my sharedpreferences from being changed?

Upvotes: 0

Views: 332

Answers (2)

Tomer Shemesh
Tomer Shemesh

Reputation: 13335

There is no way to avoid a user being able to change shared prefs. You need to implement security on your back end with session tokens so that even if the front end userid is changed the back end doesn't allow you to make requests because the session token doesnt match the user id. I assume you are asking because you are having you app communicate with a server and dont want the user to be able to see other peoples data. if not may i ask why you need to be able to do this?

read more about them here Session token - how does it work?

Upvotes: 1

user6363583
user6363583

Reputation: 104

Code like this

SharedPreference mySP = PreferenceManager.gerDefaultSharedPreference(this, Context.MODE_PRIVATE);

Only your app can access this...

Upvotes: 0

Related Questions