After the user registers, use the JAVA Implementation of the activation code

Source: Internet
Author: User

Source source http://www.java2000.net/viewthread.jsp? Tid = 4456

1. You use an algorithm to generate a random string based on the user name.
For example, it can be generated based on the current time and user name.

String username =... // This is the user name registered by the user.
String Sign = md5.encode (username + system. currenttimemillis ());

2. Save the string to your information.

User. setregisteremailsign (sign );

3. Send the email. The Link contains this string.

The email content includes a connection

<A href = ".../registeractive? Sign = <% = Sign %> "> click this link to activate your account </a>

4. When a user is activated, search for the corresponding user based on the string and then activate

// Get the activation code
String Sign = request. getparameter ("sign ");
If (! Strtools. isblank (sign ))...{
// Check whether the user with the corresponding activation code exists
Userservice US = (userservice) Factory. getbean ("userservice ");
User u = us. findbyemailsign (sign );
If (u = NULL )...{
Out. Print ("the activation code is invalid! ");
} Else if (U. isactived ())...{
Out. println ("This user is already a formal user! ");
} Else ...{
// Set the activated flag,
U. setactived (true );
If (us. Save (u )! = NULL )...{
Out. Print ("<SCRIPT> alert ('activated successfully registered successfully'); self. Location = 'login. js'; </SCRIPT> ");
} Else ...{
Out. Print ("activation failed ");
}
}
}

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.