views:

626

answers:

9

I'm trying to make a ASP.NET (C#) poll that will ask a user a Yes/No question and log that vote to the database. To prevent spam I would like to be able to make sure users can only vote once. I've thought about logging the users IP address. If this is the answer can someone give me a tutorial that shows how this can be accomplished. If this is not the answer then give me your suggestions.

Edit: I'm not asking users to register as this is not my website.

+8  A: 

You can only garuantee that each user has one vote if you can authenticate the user. So you'll need an authentication mechanism, that will allow you to prevent the user from registering multiple accounts.

I can only see this work in an environment where the user has invested something into his account, like a subscriber for an online newspaper or a reputation system as on StackOverflow.

Dave Van den Eynde
This is not a practical solution. It has no application outside of closed communities. The registration process will only hinder the votes which makes this approach counter-productive.
aleemb
+3  A: 

If you have a registered users list, send them an email containing a unique link which is generated containing a guid (for example), record the GUID in a database and match on voting.

If you are talking about generally publicly accessible and secure, then IP address on its own is not sufficient (google electronic electoral voting for the many issues involved with secure public voting).

Have you thought about using one of the free voting services?

Condorcet Internet Voting Service

EDIT: would downvoters please leave a brief comment as to why. Thanks.

Mitch Wheat
+2  A: 

IP addresses won't work for the millions of people who are working behind a proxy as well.

Cookies are a partial solution, but voting robots could just not send the cookie.

A: 

Logged in sessions are the only way to prevent double-voting fraud but since you explicitly ask for a way to log the IP address, you can get at that through:

HttpContext.Current.Request.UserHostAddress;

or

HttpContext.Current.Request.ServerVariables["REMOTE_ADDR"];

Should be easy enough to save to DB and check if IP already exists on each poll.

aleemb
That's kinda what I was looking for.
Lucas McCoy
While that gets you an IP address, on its own, it is not a particularly good indicator for voting (as I and others have mentioned)
Mitch Wheat
@Mitch Wheat, This is the standard practise. It's not fool proof but this is the accepted way of approaching the problem. Analytics suites count UUs based on the same. If you have any suggestions short of having the user register as your answer suggests, I'd like to hear about it.
aleemb
I implemented this system once and got complaints from a user because their office's traffic all came from the same IP, so it was one vote for the whole office, not person.
domus.vita
The work around is quite easy. Set a cookie so you count each user only once. You can set the cookie to expire at a relative or absolute date depending on your thresholds. That's how all analytics scripts work. Search engine spiders can also be filtered by UA string or published IP lists.
aleemb
So if someone figures out how to delete that cookie, they can vote an infinite number of times. Good job.
Dave Van den Eynde
@Dave, there is no mention of cookies in this post. Maybe you got the wrong post?
aleemb
No I'm replying to your comment just above mine, where you introduce a "work around".
Dave Van den Eynde
A: 

If the poll isn't something "critical" (for valid research, or other) I would just log the IP. If you need the poll results for something serious, I would look into Asp.Net Membership Roles.

If you log the IP, you can simply write the IP to a text file related to that poll, and search the file for the IP everytime they try to vote. (Or the same place you store your vote count)

David Anderson
+1  A: 

Have a registration that requires email confirmation of registration and make sure the email address is a unique column in the DB among your users. Then tie the vote to the email address. It won't completely prevent a sock puppet who has multiple email addresses but it will at least make it not worth the effort for most.

Turnkey
Better to generate a unique number (GUID) for each user's one time vote...
Mitch Wheat
+4  A: 

You can't limit a single vote to one IP address. An IP Address does not equal a single user. An IP address represents one or more users.

Shawn Miller
+1  A: 

A combination of IP and useragent can give you a reasonable solution.

Chris Ballance
+1  A: 

I agree that one single IP address does not correspond to a single user but I think that is the safest way of maintaining one vote per person. I usually use cookies to keep track who has voted. Of course, this is a easy hack where you can just delete the cookies and then vote again. If the vote is just some random stuff then I don't really care. If the correct votes really matter for your application then use IP address.

azamsharp