简体   繁体   中英

How do I prevent cheating when user clicks a button

So I wanted to develop a small clicker game to get my feet wet and it would also answer my question which I have in regards to cheating.

So this is the concept there is a blank page with a Button and a <h1/> There will be a registration process and the user will get put in a databse with a Score column as well as the Username & password etc.

When the user clicks on the Button I want to add a point to that user that then gets put into the Score column in the databse so that the score gets saved and also displays on the page in the h1 tag

Now if I do it through JavaScript, accessing the database through the Client and adding points from the Client then that feels like I would invite nothing but cheaters and a lot of security issues.

So my question is. How do I prevent cheaters by maybe creating a button and then hooking that up with a Function in my Controller so I can deal with it server sided.

<body>
    <h1>Playground</h1>

    <h1>Points @Model.Coins</h1>

    <h1 id="Points">0</h1>

    <button id="PointsButton">Points!</button>

    <script src="~/js/PointSystem.js"></script>
</body>

JS

let i = 1;
let button = document.getElementById("PointsButton");
let DisplayPoints = document.getElementById("Points").innerHTML;
DisplayPoints = i;

button.onclick = AddPoints;

function AddPoints() {

}

First, you should rethink whether you need to stop cheaters, secondly anything you send to the client is ultimately hackable.

It sounds like you need something from the server that authenticates the transaction as legitimate. How to do this semi-securely is really to broad of a question for this site,

If you ignore the security concern until it's necessary, you can do this via XMLHttpRequest or fetch on newer browsers.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM