JS Authentication Login Registration

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.