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 ");
}
}
}