forked from kbwood/realperson
-
Notifications
You must be signed in to change notification settings - Fork 0
/
jquery.realperson.java
44 lines (39 loc) · 1.09 KB
/
jquery.realperson.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package jquery;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* RealPerson submission processing.
*/
public class RealPerson extends HttpServlet {
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
if (rpHash(request.getParameter("defaultReal")).equals(
request.getParameter("defaultRealHash"))) {
// Accepted
}
else {
// Rejected
}
}
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
doGet(request, response);
}
/**
* Compute the hash value to check for "real person" submission.
*
* @param value the entered value
* @return its hash value
*/
private String rpHash(String value) {
int hash = 5381;
value = value.toUpperCase();
for(int i = 0; i < value.length(); i++) {
hash = ((hash << 5) + hash) + value.charAt(i);
}
return String.valueOf(hash);
}
}