Not allow localstorage to be changed by user

3.9k Views Asked by At

I use localstorage to store things like highscore in this game: http://wacky2048.ga/

If you inspect element and on the top navigation bar (where you see Elements ... Performance), then click the >> button, click Application, you can see all the localstorage items, and if you double click, you can change it. You may need to make a move and refresh.

A lot of people know this trick so the highscore becomes meaningless.

Is there any way to stop this? I store integers and JSON stringified things (in case you want to suggest a encoding method).

1

There are 1 best solutions below

2
On

The better solution would be store the data in the server. But if you really want to use localstorage consider storing the JSON as a jwt token and encrypt it using a private key which user doesn't have access. Also when your app access that data in the localstorage always check for validity. If the token is invalid, what you can do is re fetch the information from the server.

Like i said before this is more of a dumb approach. Storing data in the server would be a better solution.

Edit: To hide the private key you could use environment variables like NODE_ENV (this depends on the framework you are using)