简体   繁体   English

匿名防止单个用户进行多次投票

[英]Preventing Multiple Votes from a single user, with anonymity

I have an Android application that allows users to post information to a database, via a java web server that I have code on. 我有一个Android应用程序,允许用户通过我有代码的Java Web服务器将信息发布到数据库。

Users are allowed to up/down vote said post. 允许用户对投票发表评论。 How do I prevent the same user from voting a plethora of times on the same post? 如何防止同一用户在同一帖子上投票过多次?

A few ideas I had: 我有一些想法:

  1. Disabling locally via adding a local storage "key" for the post ID Unique Key. 通过为帖子ID唯一键添加本地存储“键”来在本地禁用。 For instance, when the user votes up or down. 例如,当用户投票赞成或反对时。 It writes a key with the information of the type of vote and the Unique Identifier of the post on the user's local storage. 它在用户的本地存储区上写有投票类型信息和帖子的唯一标识符的密钥。 Is this feasible with a lot of votes? 大量投票是否可行? Would it cause any sort of hard drive consumption/lag? 这会导致硬盘消耗/滞后吗?

  2. Storing a uniquely-generated key on the user's phone generated at application install. 在应用程序安装时生成的用户电话上存储唯一生成的密钥。 This key would be submitted to a new table in the database that associates posts with votes and the "user-key". 该密钥将被提交到数据库中的新表,该表将带有投票的帖子和“用户密钥”相关联。

If you're expecting lots of information, a database is probably the way to go. 如果您希望获得大量信息,那么数据库可能是您的最佳选择。 Obviously this will use storage space, but not much. 显然,这将占用存储空间,但不会占用太多空间。 Writing to the db tends to be very fast in my experience. 根据我的经验,写入数据库往往非常快。

The unique key would work fine too. 唯一键也可以正常工作。 That way would be more secure (depending on how you do it) since it would be harder to spoof it from the client. 这样会更安全(取决于您的操作方式),因为很难从客户端欺骗它。 If you generate the key based on the user's Google account, or the device ID, you're in good shape. 如果您根据用户的Google帐户或设备ID生成密钥,则状态良好。 If you do it by some pseudorandom method then the user could still cast multiple votes by just clearing the app data and getting a new key. 如果您通过某种伪随机方法进行操作,则用户仍然可以通过清除应用程序数据并获取新密钥来进行多次投票。

If it's really important to prevent multiple votes, do it on the server. 如果防止多次投票确实很重要,请在服务器上进行。 If it's not particularly important, do whichever method seems easier to you. 如果不是特别重要,请采用您认为更简单的方法。 You can also consider doing both, for the best of both worlds: immediate feedback to the user on a duplicate vote attempt (or just altering the UI to make it impossible), plus a backup validation on the server in case the user tries to get around the client check. 您还可以考虑同时兼顾这两个方面的优点:在重复投票尝试时立即向用户反馈(或只是更改UI以使其无法使用),以及在服务器上进行备份验证(以防用户尝试获取)围绕客户检查。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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