newTechSupport
Tuesday, August 11, 2015
HealthCare@Arogyapoint: Get Immunity to your Health- Buy now Ayurvedic cer...
HealthCare@Arogyapoint: Get Immunity to your Health- Buy now Ayurvedic cer...: Immunity is the prime requirement for Healthy life .Immune System is one of the vital factor in human body that is responsible for fightin...
Friday, July 31, 2015
HealthCare@Arogyapoint: A wide range of products offered by Arogyapoint.co...
HealthCare@Arogyapoint: A wide range of products offered by Arogyapoint.co...: frome wide range of products few of them are: ON Whey Protein 1) Each scoop contain 24 gram of protein 2) It contain 4 ...
Wednesday, July 8, 2015
Quantum operating System Coming Soon
The Reality of Dreams.. The All New Generation Quantum Computing Operating System Developed Soon, Powerful PCs Coming Soon
Quantum computing is one of the hottest topics these days and we have been covering it from time to time. This is a computation device that uses the quantum mechanical phenomenon different from the usual digital computers operating with the help of transistors.
Digital computing uses the binary digits for data encoding, whereas quantum computing uses quantum bits i.e. qubits.
What is the news about Quantum Computing? – Quantum Computing OS Developed!
Cambridge Quantum Computing (CQCL) has developed a new operating system designed to run the futuristic quantum computers. The new OS is named t|kit> (yeah, you read it correctly). This development has been possible with the help of CQCL’s very own proprietary custom designed super-fast super computer and this made the imitating of the working of a quantum processor.
“CQCL is at the forefront of developing an operating system that will allow users to harness the joint power of classical supercomputers alongside quantum computers. The development of t|ket> is a major milestone,” company said in a statement. “Quantum computing will be a reality much earlier than originally anticipated. It will have profound and far-reaching effects on a vast number of aspects of our daily lives.”
Tuesday, July 7, 2015
How to add Captcha in Java Using Google new reCaptcha
Google launched new reCaptcha for effective detection of robots. Every day hackers decrypting captchas. It became difficult for organizations to get protection from bots.
Google has given solution to this problem with new reCaptcha. In this article, I am going to explain the implementation of reCaptcha with Java
Recommended article : MintEye gives Captcha Java API for Web Application
How reCaptcha Works
- Developer has to register their website for Google recaptcha. Then developer will get application key.
- Developer has to integrate reCaptcha with registered website.
- Whenever user clicks on "I am not a robot, Google reCaptcha script will generate input value with name g-recaptcha-response.
- Whenever user submits the form, The website server receives code with parameter recaptcha-response.
- Now developer has to verify the code at server side by sending one get request to google recaptcha server with application secret key
Libraries
Get Google GSON Java Library to handle JSON responses or you can check this tutorial alsoGet reCaptcha Key
Get key
Here Site key is open, any one can see. Site key will be used in the script of HTML page. Secret key is for only application developer and it is for contacting google server sidevalidation.
HTML Code
Add google reCaptcha script
<script src='https://www.google.com/recaptcha/api.js'></script>
Add reCaptcha DIV
Google script will add input field to this div<div class="g-recaptcha" data-sitekey="6Lcsyf4SAAAAABLp3hPq6afXNfsXGxYDjCzwpbbJ"></div>
Observe below HTML code
In this below HTML google reCaptcha DIV was enclosed by form. Whenever user clicks on submit button reCaptcha input field will be submitted along with form input fields.<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Google New reCaptcha using Java</title>
</head>
<script src='https://www.google.com/recaptcha/api.js'></script>
<style type='text/css'>
.field {
padding: 0 0 10px 0;
}
.label {
padding: 3px 0;
font-weight: bold;
}
</style>
<body>
<div style="text-align: center">
<h1>Google reCaptcha using Java</h1>
</div>
<div style="width: 400px; margin: auto">
<form action="HandleRecaptcha">
<h3>Registration Form</h3>
<div class="field">
<div class="label">Enter Name</div>
<input value="" name="name" />
</div>
<div class="field">
<div class="label">Enter Email</div>
<input name="email" />
</div>
<div class="g-recaptcha"
data-sitekey="6Lcsyf4SAAAAABLp3hPq6afXNfsXGxYDjCzwpbbJ"></div>
<div class="field">
<input type="submit" value="submit" />
</div>
</form>
</div>
</body>
</html>
Java Code
CaptchaResponse.java
Pojo class to handle JSON Responsepublic class CaptchaResponse {
public boolean success;
public boolean isSuccess() {
return success;
}
public void setSuccess(boolean success) {
this.success = success;
}
}
HandleRecaptcha.java
Once user clicks on submit button, form data will be submitted to Server. Now get g-recaptcha-response parameter value.String recap = request.getParameter("g-recaptcha-response");
Now verify the g-recaptcha-response with Google server using your applicationsecret key.
URL url = new URL("https://www.google.com/recaptcha/api/siteverify?secret="+secretParameter+"&response="+recap+"&remoteip="+request.getRemoteAddr());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
String line, outputString = "";
BufferedReader reader = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
while ((line = reader.readLine()) != null) {
outputString += line;
}
System.out.println(outputString);
Now convert the response into and verify whether the input is from robot or human
CaptchaResponse capRes = new Gson().fromJson(outputString, CaptchaResponse.class);
if(capRes.isSuccess()) {
// your logic - Human
} else {
// your logic - Robot
}
Complete servlet code
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.HttpURLConnection;
import java.net.URL;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import com.google.gson.Gson;
public class HandleRecaptcha extends HttpServlet {
private static final long serialVersionUID = 1L;
private String secretParameter="Your Application Secret Code Here";
public HandleRecaptcha() {
super();
}
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// Get input parameter values (form data)
String name = request.getParameter("name");
String email = request.getParameter("email");
String recap = request.getParameter("g-recaptcha-response");
// Send get request to Google reCaptcha server with secret key
URL url = new URL("https://www.google.com/recaptcha/api/siteverify?secret="+secretParameter+"&response="+recap+"&remoteip="+request.getRemoteAddr());
HttpURLConnection conn = (HttpURLConnection) url.openConnection();
conn.setRequestMethod("GET");
String line, outputString = "";
BufferedReader reader = new BufferedReader(
new InputStreamReader(conn.getInputStream()));
while ((line = reader.readLine()) != null) {
outputString += line;
}
System.out.println(outputString);
// Convert response into Object
CaptchaResponse capRes = new Gson().fromJson(outputString, CaptchaResponse.class);
request.setAttribute("name", name);
request.setAttribute("email", email);
// Verify whether the input from Human or Robot
if(capRes.isSuccess()) {
// Input by Human
request.setAttribute("verified", "true");
} else {
// Input by Robot
request.setAttribute("verified", "false");
}
request.getRequestDispatcher("/response.jsp").forward(request, response);
}
}
If You Enjoyed This, Take 5 Seconds To Share It
Location:
India
Subscribe to:
Posts (Atom)