JS Authentication Login Registration Advantages, direct authentication in the foreground, do not need to read back in the background data validation, reduce server pressure.
Login verification is necessary to intercept the malicious script logon registration attack.
The JS code is as follows:
$ (document). Ready (function () {
var result=0;
var show= "";
var Inresult;
var Tag=false;
Getarithmetic ();
/**
* Change the verification code arithmetic type
*/
$ (document). On ("click", "#sswitch", function () {
Getarithmetic ();
});
/**
*
*/
$ (document). On ("Blur", "#result", function () {
inresult=$ ("#result"). Val ();
if (Result!=inresult) {
$ ("#result"). Parent (). Next (). HTML ("");
$ ("#result"). Parent (). Next (). HTML ("wrong answer");
}
if (inresult== "") {
$ ("#result"). Parent (). Next (). HTML ("");
$ ("#result"). Parent (). Next (). HTML ("The answer cannot be empty!"). ");
}
if (Inresult==result) {
$ ("#result"). Parent (). Next (). HTML ("");
$ ("#result"). Parent (). Next (). HTML ("validation passed!"). ");
Tag=true;
}
});
/**
* Generate validation arithmetic type
*/
function Getarithmetic () {
Tag=false;
var a=parseint (Math.random () *10);//Generate 0-10 of random numbers, can be generated to 100 increase computational difficulty
var b=parseint (Math.random () *10);
var N1=math.floor (Math.random () *3+1);//output 1~4 between the random integer, save the removal method, so change to 3
if (n1==1) {
Result=a+b;
show=a+ "+" +b+ "=";
}
if (n1==2) {
Result=a-b;
show=a+ "-" +b+ "=";
}
if (n1==3) {
Result=a*b;
show=a+ "*" +b+ "=";
}
/* if (n1==4) {
result=a/b;
show=a+ "/" +b+ "=";
alert (result);
}*/
$ ("#show"). Val (show);
$ ("#show"). HTML (show);
}
});
Page effect:
JS Authentication Login Registration