Remember the password and automatically log on to the instance based on the localStorge development logon module,

Source: Internet
Author: User

Remember the password and automatically log on to the instance based on the localStorge development logon module,

This is the debut of the functional modules of this module. Why? One day in the group, a buddy said that he had a private activity and developed a *** module. I chatted with him that day, and then, I decided to create this module for her. I talked to him about the delivery time. He said that at least two days later, and then he talked about how to add a new one. Finally, we reached it, 500 RMB !!! I actually developed this module on the first night. At that time, I told him that the function module development is OK. Do you want to check it remotely? If no problem exists, I will submit it, after a while, he returned to me. After that, he sent it, and then turned it to 500 RMB. At that time, he was surprised. After all, it was a, And then he handed over the project to him, and it was a perfect delivery, there is no problem with the customer! Now, I'm so excited! Record the time-2016-3.

Abstract: Remember the password and automatic login module of the drive are based on cookies. However, if you do so on cookies, the cookie file size is limited, therefore, this article describes how to automatically log on and remember the password Based on the storge on H5 and the local persistent storage. If you do not understand storge, we recommend that you charge it first!

Charging: learn more about localstorge

Note: This is a webpage-like logon module. If you want the complete source code, contact the bird.

:

Core source code sharing:

<! DOCTYPE html> 

Summary:

This module is common. What we need to do is:

1. When a user clicks log on, he first obtains the data in the form.
2. Make a judgment to determine whether the user selects the check box to remember the password or log on automatically

3. If this option is not selected, encrypt the data and send it to the server for Logon verification. Then, return

4. If you select Remember password, save the user name and password to storge. The core code is as follows:

Var storage = window. localStorage; // remember the password if (document. getElementById ("isRemberPwdId "). checked) {// store to loaclStage // alert (134); storage ["email"] = userEmail; storage ["password"] = userPassWord; storage ["isstorePwd"] = "yes";} else {storage ["email"] = userEmail; storage ["isstorePwd"] = "no ";}

Remember, now you have checked the Remember password. What should you do next time you log on?

Make a judgment in $ (function () {}), that is, when the browser renders the tag. Check whether storge ['isstorepwd '] is yes. Like the core code.

$ (Document ). ready (function () {// read the local storage of localStage and fill in the username and password. If there is a value for automatic logon, Jump directly; // On the contrary, jump to this page, waiting for login to process var storage = window. localStorage; var getEmail = storage ["email"]; var getPwd = storage ["password"]; var getisstroepwd = storage ["isstorePwd"]; var getisautologin = storage ["isautologin"]; if ("yes" = getisstroepwd) {if ("yes" = getisautologin ){....}} else {$ ("# email "). val (getEmail); $ ("# password "). val (getPwd); document. getElementById ("isRemberPwdId "). checked = true ;}}});

OK. You can do it if you remember the password!

5. Automatic Logon: Do I still use this function? Similar to remembering a password!

// Automatically log on to if (document. getElementById ("isAutoLoginId "). checked) {// store to loaclStage storage ["email"] = userEmail; storage ["password"] = userPassWord; // Save the password to storage ["isstorePwd"] = "yes"; storage ["isautologin"] = "yes";} else {storage ["email"] = userEmail; storage ["isautologin"] = "no ";}

When the user logs on again, it still makes a judgment when loading, whether to check automatic login, if checked, get data from storage, asynchronous occurs directly

The user does not need to make a click logon event!

If ("yes" = getisautologin) {if (((""! = GetEmail) | (null! = GetEmail ))&&((""! = GetPwd) | (null! = GetPwd) {// The lacoste has saved the login information and logs in directly. // alert ('automatic loging'); $ ("# email "). val (getEmail); $ ("# password "). val (getPwd); // window. location = ""; // displayed when loading: Automatic Login $. ajax ({url: 'loginservlet. ashx ', data: {email: getEmail, password: getPwd}, dataType: 'json', success: function (data) {if (data. msg = "") {alert ("account information exception, please verify and log on again");} else {// alert (123); // Save the session after successful logon, if you remember the password, save it to the local window. location. href = 'default2. aspx ';}}, error: function () {alert ("system error ");}});

The above Code, based on the localStorge development login module, remembers the password and the automatic login instance, which is all the content shared by Alibaba Cloud. I hope to give you a reference and support for the customer's house.

Related Article

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.