Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

A simple voting system: how to prevent duplicate votes [duplicate]

I'm building a simple web app with an up-vote option. I plan on offering cash rewards for the most up-voted so I want a relatively secure system. I have a couple questions about conception. I know that my post is similar to a few others but none seem to be specific enough to the platform to put my mind at ease.

My web app is utilizing javascript and firebase for loading all of the objects that are being voted on. I'm going to force a user to be logged in and store IP addresses, user IDs etc.

Questions:

  • Is this fundamentally flawed from the start for using javascript? I see a large potential for writing a script that just changes values and re-votes. (maybe I can verify the front end data is correct and that the user exists with an ajax call?)
  • With the off-beat chance my app becomes successful Is this going to be too much front end computing?

Edit: I'm sorry, but I left out the key fact that I do have a larger back end system(WordPress) that handles authentication. The app I'm working on is largely independent from wordpress. I'm simply pulling some user information for filtering purposes. I chose Firebase as a storage solution for its real-time features.

I'm hoping to combat voter fraud with a few methods:

  • low rewards $100/month given away.
  • being logged in isn't a compromise, I actually want users to be registered and verified with human eyes to be eligible to vote. Others can witness the contest but cannot vote.
  • server-side checks. If my app gains popularity I can write scripts to monitor voting patterns for irregularities? if someone is abusing the system, I disable their ability to win.
like image 651
Front_End_Dev Avatar asked May 31 '13 18:05

Front_End_Dev


People also ask

What are 3 methods of voting?

The regular methods of voting in such bodies are a voice vote, a rising vote, and a show of hands. Additional forms of voting include a recorded vote and balloting. The assembly could decide on the voting method by adopting a motion on it. Different legislatures may have their voting methods.

What happens during the second vote?

In the second round, because there are only two candidates, and absent a tie vote, one candidate will achieve an absolute majority. Voters may change the candidate they support in the second round.

What is a dummy in voting?

A dummy is any player, regardless of their weight, who has no say in the outcome of the election. A player without any say in the outcome is a player without power. Consider the weighted voting system [8: 4, 4, 2, 1].


2 Answers

It is certainly possible to do this securely client-side. However, as noted by others, it does require users to login. If you're already using Firebase, this is actually pretty easy to implement using the FirebaseAuthClient.

You can then couple this with Firebase security rules to enforce that any logged in user can only upvote once. Check out the screencast on the security page for an example!

Your security rules might look like:

{
  "rules": {
    "users:" {
      "$userid": {
        "voted_on": {
          "$articleid": {
            ".write": "!data.exists()"
          }
        }
      }
    }
  }
}

This ensures that you can write any given value to /users/anant/voted_on/article1 exactly once. You can add a .validate rule to ensure that the value is a boolean (or something else).

like image 114
Anant Avatar answered Oct 21 '22 03:10

Anant


This is what you should probably do:

1) As soon as user votes, you should make an ajax call to the server and update the flag in the database and disable the voting using javascript.

2) If the user refreshes the page and tries to vote up again, the server would be knowing that the vote has already been made(as it is saved in database) so the voting system will appear disabled on the page.

3) If the user tries to enable the voting using chrome tools or firebug by modifying the source of page, you can create a check at database end by setting the composite key on userID and "vote" flag which would prevent the duplicate votes.

Hope it helps..

like image 3
writeToBhuwan Avatar answered Oct 21 '22 04:10

writeToBhuwan