jquery implementation of the login page of the Remember password

Source: Internet
Author: User

First, you extract the asynchronous validation of a button click event as a separate function, you need to extract the variables in the button click event to define as global variables and add a variable editpass (to mark whether you're typing your password or a password read from a cookie).

The code is as follows Copy Code

var wrongtypename,//user name error type, can be directly as an error message array subscript
WRONGTYPEPWD,//user password error type
wrongnamehtml = new Array ("", "Please enter user name", "User name length is too short", "username is over 12 digits", "your username or password is wrong", "timeout, please login again"),
wrongpwdhtml = new Array ("", "Enter password", "password length is less than 6 digits", "", "password contains illegal characters"),
Editpass=false;

button click event Start

The code is as follows Copy Code

$ (". Btn-submit"). Click (function () {
Wrongtypename = 0;
wrongtypepwd = 0;
var uname = $ ("#uname"). Val (),//user name
PWD = $ ("#passwd"). Val (),//user password
Plength = Pwd.length,
Nlength = Uname.length; Length
if (nlength = 0)
Wrongtypename = 1;
if (nlength > 0 && nlength < 2)
Wrongtypename = 2;
if (Nlength > 20)
Wrongtypename = 3;
if (plength = 0)
Wrongtypepwd = 1; Here is a judgment of the length of the username and password, and gets the subscript for the array of error messages.
else {
var patrn =/^ (w) {6,20}$/;
if (Plength < 6)
Wrongtypepwd = 2;
if (Plength > 50)
Wrongtypepwd = 3;
if (Plength > 6 && plength < 20) {
if (!patrn.exec (PWD))
Wrongtypepwd = 4; Here is a front-end judgment of the legality of the user's password and returns the subscript of the error array
}
}
Inputtip (0, wrongnamehtml, wrongtypename);
Inputtip (1, wrongpwdhtml, wrongtypepwd);

if (wrongtypepwd = = 0 && wrongtypename = 0) {/////when user input information is completely legitimate, that is, the array subscript is all 0 begin to perform AJAX validation
Alert ($.cookie ("logout"));
if (Editpass) {
PWD = $.MD5 (pwd);
}
$ ("#passwd"). Val (pwd);
$ ("#login-form input"). attr (' disabled ', true);
$ ('. Remember '). Unbind (' click ');
Information has been submitted to the server, so all the input box buttons on the page are set to unavailable so that you can effectively avoid duplicate submissions
var remb = $ (' #remember-long '). Val ();
Ajaxcheck (uname, PWD, REMB);
}
});

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.