Java Web implementation forgot password (retrieve password) function and code

Source: Internet
Author: User
Tags decrypt

Java Web implementation forgot password (retrieve password) function and code

(i). General ideas

(b). part

(iii). Part of the Code

(i). General ideas:

1. In the Recover Password page input name, email and verification code, enter and click the "Submit" button, at this time send a message, the message with the encrypted link.

2. Click the link in the message to decrypt and determine if the link is valid, and verify that it is passed to the Change Password page.

3. Enter the new password in the edit page, click "Modify button" To change the password, the operation is completed.

(b). Part:

(c). Part of the code:

Code 1 (corresponding to the above general idea 1): The key here is to generate an encrypted link, and this link parameter needs to be passed in the browser get way, cannot support "+", "/" and other special characters.

                    // Add expiration time, link                expires after 24 hours long endtimes = System.currenttimemillis () +1*24*3600*1000;                 = personname+ ";" +email+ ";" +endtimes;                 // first encryption, then URL transcoding, the order cannot be modified modify by Lifq 20150317                String encode = urlutil.geturlencoderstring (DESUTIL.ENCRYPT (para));                 = Emailutil.replace (Content, "{email_setpwd_add2}", "http://localhost:8080/test/toSetPayrollPwd2.do?vc=" +encode);

Code 2 (corresponding to the above general idea 2): Here the key is to get the parameter VC and decrypt.

/*** Retrieve password Second step * *@returnString *@authorLifq * @date 2015-3-17 a.m. 10:24:09*/     Publicstring ToSetPayrollPwd2 () {string VC= Context.getparameter ("VC"); if(NULL!=VC) {            Try {                //here direct des decodingString decode =Desutil.decrypt (VC); List List= Emailutil.parsecontent (decode, ";")); if(NULL!=list && list.size () >0) {String personname= (String) list.get (0); String Email= (String) list.get (1); LongEntimes = Long.parselong (String) List.get (2)); LongCurtime =System.currenttimemillis (); if(entimes<=curtime) {Context.setrequestattribute ("ErrorMsg", "The current link has expired, please re-reset the password link!" "); }Else{Context.setrequestattribute ("PersonName", PersonName); Context.setrequestattribute ("Email", email); Context.setrequestattribute ("VC", Urlutil.geturlencoderstring (VC)); }                }            } Catch(Exception e) {e.printstacktrace (); Context.setrequestattribute ("ErrorMsg", "Link invalid!" "); }        }        returnreturn_success; }

The above section involves URL encryption and decryption of the Util class and Des encryption, decryption of the Util class, in the previous article has the code:

1.java implementation des encryption and decryption algorithm

2.java Implementing URL transcoding decoding

Java Web implementation forgot password (retrieve password) function and code

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.